document-dataply 0.0.9-alpha.3 → 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 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 compareValue(a.v, b.v);
10101
+ return comparePrimaryValue(a.v, b.v);
10087
10102
  }
10088
10103
  asc(a, b) {
10089
10104
  const diff = compareValue(a.v, b.v);
@@ -10417,19 +10432,39 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
10417
10432
  * Convert CreateIndexOption to IndexMetaConfig for metadata storage.
10418
10433
  */
10419
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
+ }
10420
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
+ }
10421
10450
  return {
10422
10451
  type: "btree",
10423
10452
  fields: option.fields
10424
10453
  };
10425
10454
  }
10426
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
+ }
10427
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
+ }
10428
10463
  return {
10429
10464
  type: "fts",
10430
10465
  fields: option.fields,
10431
10466
  tokenizer: "ngram",
10432
- gramSize: option.ngram
10467
+ gramSize: option.gramSize
10433
10468
  };
10434
10469
  }
10435
10470
  return {
@@ -10706,9 +10741,10 @@ var DocumentDataplyAPI = class extends import_dataply3.DataplyAPI {
10706
10741
  const currentVersion = innerMetadata.schemeVersion ?? 0;
10707
10742
  if (currentVersion < version) {
10708
10743
  await callback(tx2);
10709
- innerMetadata.schemeVersion = version;
10710
- innerMetadata.updatedAt = Date.now();
10711
- await this.updateDocumentInnerMetadata(innerMetadata, tx2);
10744
+ const freshMetadata = await this.getDocumentInnerMetadata(tx2);
10745
+ freshMetadata.schemeVersion = version;
10746
+ freshMetadata.updatedAt = Date.now();
10747
+ await this.updateDocumentInnerMetadata(freshMetadata, tx2);
10712
10748
  }
10713
10749
  }, tx);
10714
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
- ngram: number;
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",
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>",