document-dataply 0.0.9-alpha.2 → 0.0.9-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/cjs/index.js +47 -7
- package/dist/types/types/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -10081,9 +10081,24 @@ function compareValue(a, b) {
|
|
|
10081
10081
|
}
|
|
10082
10082
|
return aList.length - bList.length;
|
|
10083
10083
|
}
|
|
10084
|
+
function comparePrimaryValue(a, b) {
|
|
10085
|
+
const aArr = Array.isArray(a);
|
|
10086
|
+
const bArr = Array.isArray(b);
|
|
10087
|
+
if (!aArr && !bArr) {
|
|
10088
|
+
return comparePrimitive(a, b);
|
|
10089
|
+
}
|
|
10090
|
+
const aList = aArr ? a : [a];
|
|
10091
|
+
const bList = bArr ? b : [b];
|
|
10092
|
+
const len = Math.min(aList.length, bList.length);
|
|
10093
|
+
for (let i = 0; i < len; i++) {
|
|
10094
|
+
const diff = comparePrimitive(aList[i], bList[i]);
|
|
10095
|
+
if (diff !== 0) return diff;
|
|
10096
|
+
}
|
|
10097
|
+
return 0;
|
|
10098
|
+
}
|
|
10084
10099
|
var DocumentValueComparator = class extends import_dataply2.ValueComparator {
|
|
10085
10100
|
primaryAsc(a, b) {
|
|
10086
|
-
return
|
|
10101
|
+
return comparePrimaryValue(a.v, b.v);
|
|
10087
10102
|
}
|
|
10088
10103
|
asc(a, b) {
|
|
10089
10104
|
const diff = compareValue(a.v, b.v);
|
|
@@ -10245,8 +10260,12 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
10245
10260
|
throw new Error("Document metadata verification failed");
|
|
10246
10261
|
}
|
|
10247
10262
|
const metadata = await this.getDocumentInnerMetadata(tx);
|
|
10248
|
-
const targetIndices = /* @__PURE__ */ new Map(
|
|
10249
|
-
|
|
10263
|
+
const targetIndices = /* @__PURE__ */ new Map([
|
|
10264
|
+
["_id", { type: "btree", fields: ["_id"] }]
|
|
10265
|
+
]);
|
|
10266
|
+
for (const [name, info] of Object.entries(metadata.indices)) {
|
|
10267
|
+
targetIndices.set(name, info[1]);
|
|
10268
|
+
}
|
|
10250
10269
|
for (const [name, option] of this.pendingCreateIndices) {
|
|
10251
10270
|
const config = this.toIndexMetaConfig(option);
|
|
10252
10271
|
targetIndices.set(name, config);
|
|
@@ -10413,19 +10432,39 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
10413
10432
|
* Convert CreateIndexOption to IndexMetaConfig for metadata storage.
|
|
10414
10433
|
*/
|
|
10415
10434
|
toIndexMetaConfig(option) {
|
|
10435
|
+
if (!option || typeof option !== "object") {
|
|
10436
|
+
throw new Error("Index option must be a non-null object");
|
|
10437
|
+
}
|
|
10438
|
+
if (!option.type) {
|
|
10439
|
+
throw new Error('Index option must have a "type" property ("btree" or "fts")');
|
|
10440
|
+
}
|
|
10416
10441
|
if (option.type === "btree") {
|
|
10442
|
+
if (!Array.isArray(option.fields) || option.fields.length === 0) {
|
|
10443
|
+
throw new Error('btree index requires a non-empty "fields" array');
|
|
10444
|
+
}
|
|
10445
|
+
for (let i = 0; i < option.fields.length; i++) {
|
|
10446
|
+
if (typeof option.fields[i] !== "string" || option.fields[i].length === 0) {
|
|
10447
|
+
throw new Error(`btree index "fields[${i}]" must be a non-empty string, got: ${JSON.stringify(option.fields[i])}`);
|
|
10448
|
+
}
|
|
10449
|
+
}
|
|
10417
10450
|
return {
|
|
10418
10451
|
type: "btree",
|
|
10419
10452
|
fields: option.fields
|
|
10420
10453
|
};
|
|
10421
10454
|
}
|
|
10422
10455
|
if (option.type === "fts") {
|
|
10456
|
+
if (typeof option.fields !== "string" || option.fields.length === 0) {
|
|
10457
|
+
throw new Error(`fts index requires a non-empty string "fields", got: ${JSON.stringify(option.fields)}`);
|
|
10458
|
+
}
|
|
10423
10459
|
if (option.tokenizer === "ngram") {
|
|
10460
|
+
if (typeof option.gramSize !== "number" || option.gramSize < 1) {
|
|
10461
|
+
throw new Error(`fts ngram index requires a positive "gramSize" number, got: ${JSON.stringify(option.gramSize)}`);
|
|
10462
|
+
}
|
|
10424
10463
|
return {
|
|
10425
10464
|
type: "fts",
|
|
10426
10465
|
fields: option.fields,
|
|
10427
10466
|
tokenizer: "ngram",
|
|
10428
|
-
gramSize: option.
|
|
10467
|
+
gramSize: option.gramSize
|
|
10429
10468
|
};
|
|
10430
10469
|
}
|
|
10431
10470
|
return {
|
|
@@ -10702,9 +10741,10 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
|
|
|
10702
10741
|
const currentVersion = innerMetadata.schemeVersion ?? 0;
|
|
10703
10742
|
if (currentVersion < version) {
|
|
10704
10743
|
await callback(tx2);
|
|
10705
|
-
|
|
10706
|
-
|
|
10707
|
-
|
|
10744
|
+
const freshMetadata = await this.getDocumentInnerMetadata(tx2);
|
|
10745
|
+
freshMetadata.schemeVersion = version;
|
|
10746
|
+
freshMetadata.updatedAt = Date.now();
|
|
10747
|
+
await this.updateDocumentInnerMetadata(freshMetadata, tx2);
|
|
10708
10748
|
}
|
|
10709
10749
|
}, tx);
|
|
10710
10750
|
}
|
|
@@ -151,7 +151,7 @@ export type CreateIndexFTSOption<T extends DocumentJSON> = {
|
|
|
151
151
|
type: 'fts';
|
|
152
152
|
fields: DeepFlattenKeys<DataplyDocument<T>> & string;
|
|
153
153
|
tokenizer: 'ngram';
|
|
154
|
-
|
|
154
|
+
gramSize: number;
|
|
155
155
|
};
|
|
156
156
|
export type CreateIndexOption<T extends DocumentJSON> = CreateIndexBTreeOption<T> | CreateIndexFTSOption<T>;
|
|
157
157
|
export interface DocumentDataplyOptions extends DataplyOptions {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "document-dataply",
|
|
3
|
-
"version": "0.0.9-alpha.
|
|
3
|
+
"version": "0.0.9-alpha.4",
|
|
4
4
|
"description": "Simple and powerful JSON document database supporting complex queries and flexible indexing policies.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "izure <admin@izure.org>",
|