edinburgh 0.5.0 → 0.6.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 +309 -246
- package/build/src/datapack.d.ts +9 -9
- package/build/src/datapack.js +9 -9
- package/build/src/edinburgh.d.ts +21 -7
- package/build/src/edinburgh.js +53 -67
- package/build/src/edinburgh.js.map +1 -1
- package/build/src/indexes.d.ts +85 -205
- package/build/src/indexes.js +150 -503
- package/build/src/indexes.js.map +1 -1
- package/build/src/migrate.js +8 -10
- package/build/src/migrate.js.map +1 -1
- package/build/src/models.d.ts +152 -107
- package/build/src/models.js +433 -144
- package/build/src/models.js.map +1 -1
- package/build/src/types.d.ts +30 -48
- package/build/src/types.js +25 -24
- package/build/src/types.js.map +1 -1
- package/build/src/utils.d.ts +4 -4
- package/build/src/utils.js +4 -4
- package/package.json +2 -2
- package/skill/AnyModelClass.md +7 -0
- package/skill/FindOptions.md +37 -0
- package/skill/Lifecycle Hooks.md +24 -0
- package/skill/{Model_delete.md → Lifecycle Hooks_delete.md } +1 -1
- package/skill/{Model_getPrimaryKeyHash.md → Lifecycle Hooks_getPrimaryKeyHash.md } +1 -1
- package/skill/{Model_isValid.md → Lifecycle Hooks_isValid.md } +1 -1
- package/skill/Lifecycle Hooks_migrate.md +26 -0
- package/skill/{Model_preCommit.md → Lifecycle Hooks_preCommit.md } +2 -2
- package/skill/{Model_preventPersist.md → Lifecycle Hooks_preventPersist.md } +1 -1
- package/skill/{Model_validate.md → Lifecycle Hooks_validate.md } +2 -2
- package/skill/ModelBase.md +7 -0
- package/skill/ModelClass.md +8 -0
- package/skill/SKILL.md +180 -132
- package/skill/Schema Evolution.md +19 -0
- package/skill/TypeWrapper_containsNull.md +11 -0
- package/skill/TypeWrapper_deserialize.md +9 -0
- package/skill/TypeWrapper_getError.md +11 -0
- package/skill/TypeWrapper_serialize.md +10 -0
- package/skill/TypeWrapper_serializeType.md +9 -0
- package/skill/array.md +2 -2
- package/skill/defineModel.md +3 -2
- package/skill/deleteEverything.md +8 -0
- package/skill/field.md +3 -3
- package/skill/link.md +3 -3
- package/skill/literal.md +1 -1
- package/skill/opt.md +1 -1
- package/skill/or.md +1 -1
- package/skill/record.md +1 -1
- package/skill/set.md +2 -2
- package/skill/setOnSaveCallback.md +5 -2
- package/skill/transact.md +1 -1
- package/src/datapack.ts +9 -9
- package/src/edinburgh.ts +68 -68
- package/src/indexes.ts +251 -599
- package/src/migrate.ts +9 -10
- package/src/models.ts +528 -231
- package/src/types.ts +36 -34
- package/src/utils.ts +4 -4
- package/skill/BaseIndex.md +0 -16
- package/skill/BaseIndex_batchProcess.md +0 -10
- package/skill/BaseIndex_find.md +0 -7
- package/skill/BaseIndex_find_2.md +0 -7
- package/skill/BaseIndex_find_3.md +0 -7
- package/skill/BaseIndex_find_4.md +0 -7
- package/skill/Model.md +0 -20
- package/skill/Model_batchProcess.md +0 -8
- package/skill/Model_migrate.md +0 -32
- package/skill/Model_replaceInto.md +0 -16
- package/skill/NonPrimaryIndex.md +0 -10
- package/skill/SecondaryIndex.md +0 -9
- package/skill/UniqueIndex.md +0 -9
- package/skill/dump.md +0 -8
package/src/migrate.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as lowlevel from "olmdb/lowlevel";
|
|
2
2
|
import DataPack from "./datapack.js";
|
|
3
|
-
import {
|
|
3
|
+
import { currentTxn, type Transaction, transact } from "./edinburgh.js";
|
|
4
|
+
import { modelRegistry } from "./models.js";
|
|
4
5
|
import { dbDel, toBuffer, bytesEqual } from "./utils.js";
|
|
5
6
|
import { deserializeType, TypeWrapper } from "./types.js";
|
|
6
|
-
import { transact } from "./edinburgh.js";
|
|
7
7
|
|
|
8
8
|
const INDEX_ID_PREFIX = -2;
|
|
9
9
|
|
|
@@ -123,7 +123,7 @@ export async function runMigration(options: MigrationOptions = {}): Promise<Migr
|
|
|
123
123
|
if (options.tables && !options.tables.includes(model.tableName)) continue;
|
|
124
124
|
knownIndexIds.add(model._indexId!);
|
|
125
125
|
modelByPkIndexId.set(model._indexId!, model);
|
|
126
|
-
for (const sec of model._secondaries ||
|
|
126
|
+
for (const sec of Object.values(model._secondaries || {})) {
|
|
127
127
|
knownIndexIds.add(sec._indexId!);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
@@ -157,7 +157,7 @@ export async function runMigration(options: MigrationOptions = {}): Promise<Migr
|
|
|
157
157
|
let secondaryCount = 0;
|
|
158
158
|
let rewrittenCount = 0;
|
|
159
159
|
const migrateFn = (model as any).migrate as ((record: Record<string, any>) => void) | undefined;
|
|
160
|
-
const secondaries = model._secondaries ||
|
|
160
|
+
const secondaries = Object.values(model._secondaries || {});
|
|
161
161
|
|
|
162
162
|
await forEachRow(indexId, (txn, keyBuf, valueBuf) => {
|
|
163
163
|
const valuePack = new DataPack(valueBuf);
|
|
@@ -170,7 +170,7 @@ export async function runMigration(options: MigrationOptions = {}): Promise<Migr
|
|
|
170
170
|
const record: Record<string, any> = {};
|
|
171
171
|
const keyPack = new DataPack(keyBuf);
|
|
172
172
|
keyPack.readNumber(); // skip indexId
|
|
173
|
-
for (const [name, type] of model.
|
|
173
|
+
for (const [name, type] of model._indexFields.entries()) {
|
|
174
174
|
record[name] = type.deserialize(keyPack);
|
|
175
175
|
}
|
|
176
176
|
for (const [name, type] of versionInfo.nonKeyFields.entries()) {
|
|
@@ -189,14 +189,14 @@ export async function runMigration(options: MigrationOptions = {}): Promise<Migr
|
|
|
189
189
|
sec._write(txn, keyBuf, record as any);
|
|
190
190
|
secondaryCount++;
|
|
191
191
|
} else if (preMigrate) {
|
|
192
|
-
if (sec._update(txn, keyBuf, record, preMigrate)) secondaryCount++;
|
|
192
|
+
if (sec._update(txn, keyBuf, record as any, preMigrate)) secondaryCount++;
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
// Rewrite primary row data to current version
|
|
198
198
|
if (rewriteData) {
|
|
199
|
-
model.
|
|
199
|
+
model._writePK(txn, keyBuf, record);
|
|
200
200
|
rewrittenCount++;
|
|
201
201
|
}
|
|
202
202
|
});
|
|
@@ -224,7 +224,6 @@ export async function runMigration(options: MigrationOptions = {}): Promise<Migr
|
|
|
224
224
|
const failures: Record<string, number> = {};
|
|
225
225
|
|
|
226
226
|
await forEachRow(oldDef.id, (txn, keyBuf) => {
|
|
227
|
-
let instance;
|
|
228
227
|
try {
|
|
229
228
|
// Deserialize old key
|
|
230
229
|
const keyPack = new DataPack(keyBuf);
|
|
@@ -239,7 +238,7 @@ export async function runMigration(options: MigrationOptions = {}): Promise<Migr
|
|
|
239
238
|
if (migrateFn) migrateFn(record);
|
|
240
239
|
|
|
241
240
|
// _write validates, checks duplicates, writes primary + secondaries
|
|
242
|
-
instance = new (model as any)(record, txn);
|
|
241
|
+
let instance = new (model as any)(record, txn);
|
|
243
242
|
instance._write(txn);
|
|
244
243
|
dbDel(txn.id, keyBuf);
|
|
245
244
|
converted++;
|
|
@@ -250,7 +249,7 @@ export async function runMigration(options: MigrationOptions = {}): Promise<Migr
|
|
|
250
249
|
failures['error'] = (failures['error'] || 0) + 1;
|
|
251
250
|
}
|
|
252
251
|
} finally {
|
|
253
|
-
|
|
252
|
+
txn.instances.clear(); // We've already handled the _write() ourselves
|
|
254
253
|
}
|
|
255
254
|
});
|
|
256
255
|
|