document-dataply 0.0.2-alpha.0 → 0.0.2-alpha.2
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 +38 -18
- package/dist/types/types/index.d.ts +16 -5
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -7225,6 +7225,7 @@ var DocumentDataply = class {
|
|
|
7225
7225
|
lte: "primaryLte",
|
|
7226
7226
|
gt: "primaryGt",
|
|
7227
7227
|
gte: "primaryGte",
|
|
7228
|
+
or: "primaryOr",
|
|
7228
7229
|
like: "like"
|
|
7229
7230
|
};
|
|
7230
7231
|
constructor(file, options) {
|
|
@@ -7253,7 +7254,7 @@ var DocumentDataply = class {
|
|
|
7253
7254
|
for (const field in query) {
|
|
7254
7255
|
const conditions = query[field];
|
|
7255
7256
|
let newConditions;
|
|
7256
|
-
if (typeof conditions !== "object") {
|
|
7257
|
+
if (typeof conditions !== "object" || conditions === null) {
|
|
7257
7258
|
newConditions = { primaryEqual: { v: conditions } };
|
|
7258
7259
|
} else {
|
|
7259
7260
|
newConditions = {};
|
|
@@ -7262,7 +7263,11 @@ var DocumentDataply = class {
|
|
|
7262
7263
|
const after = this.operatorConverters[before];
|
|
7263
7264
|
const v = conditions[before];
|
|
7264
7265
|
if (!after) continue;
|
|
7265
|
-
|
|
7266
|
+
if (before === "or" && Array.isArray(v)) {
|
|
7267
|
+
newConditions[after] = v.map((val) => ({ v: val }));
|
|
7268
|
+
} else {
|
|
7269
|
+
newConditions[after] = { v };
|
|
7270
|
+
}
|
|
7266
7271
|
}
|
|
7267
7272
|
}
|
|
7268
7273
|
result[field] = newConditions;
|
|
@@ -7282,7 +7287,10 @@ var DocumentDataply = class {
|
|
|
7282
7287
|
const condition = query[field];
|
|
7283
7288
|
candidates.push({ tree, condition });
|
|
7284
7289
|
}
|
|
7285
|
-
|
|
7290
|
+
let res = import_dataply3.BPTreeAsync.ChooseDriver(candidates);
|
|
7291
|
+
if (!res && candidates.length > 0) {
|
|
7292
|
+
res = candidates[0];
|
|
7293
|
+
}
|
|
7286
7294
|
if (!res) return null;
|
|
7287
7295
|
return {
|
|
7288
7296
|
driver: {
|
|
@@ -7336,30 +7344,42 @@ var DocumentDataply = class {
|
|
|
7336
7344
|
const verbose = this.verboseQuery(query);
|
|
7337
7345
|
const selectivity = await this.getSelectivityCandidate(verbose);
|
|
7338
7346
|
if (!selectivity) return [];
|
|
7339
|
-
const
|
|
7347
|
+
const documents = [];
|
|
7340
7348
|
const { driver, others } = selectivity;
|
|
7341
|
-
const stream = driver.
|
|
7349
|
+
const stream = driver.condition.primaryOr ? (async function* () {
|
|
7350
|
+
const values = driver.condition.primaryOr;
|
|
7351
|
+
for (const val of values) {
|
|
7352
|
+
const nodes = await driver.tree.where({ primaryEqual: val });
|
|
7353
|
+
for (const [pk, node] of nodes) {
|
|
7354
|
+
yield [pk, node];
|
|
7355
|
+
}
|
|
7356
|
+
}
|
|
7357
|
+
})() : driver.condition.primaryNotEqual ? (async function* (api) {
|
|
7358
|
+
const idTree = await api.ensureTree("_id");
|
|
7359
|
+
const nodes = idTree.whereStream({ primaryGte: { v: 0 } });
|
|
7360
|
+
for await (const [pk, node] of nodes) {
|
|
7361
|
+
yield [pk, node];
|
|
7362
|
+
}
|
|
7363
|
+
})(this.api) : driver.tree.whereStream(driver.condition);
|
|
7342
7364
|
for await (const [pk, val] of stream) {
|
|
7365
|
+
const stringify = await this.api.select(pk, false, tx2);
|
|
7366
|
+
if (!stringify) continue;
|
|
7367
|
+
const doc = JSON.parse(stringify);
|
|
7368
|
+
const flattenedDoc = this.api.flattenDocument(doc);
|
|
7343
7369
|
let isMatch = true;
|
|
7344
|
-
|
|
7345
|
-
|
|
7346
|
-
|
|
7370
|
+
const verificationList = driver.condition.primaryNotEqual ? [...others, driver] : others;
|
|
7371
|
+
for (const { tree, condition } of verificationList) {
|
|
7372
|
+
const field = tree.strategy.treeKey;
|
|
7373
|
+
const fieldValue = flattenedDoc[field];
|
|
7374
|
+
if (!tree.verify({ k: pk, v: fieldValue }, condition)) {
|
|
7347
7375
|
isMatch = false;
|
|
7348
7376
|
break;
|
|
7349
7377
|
}
|
|
7350
7378
|
}
|
|
7351
7379
|
if (isMatch) {
|
|
7352
|
-
|
|
7353
|
-
if (
|
|
7354
|
-
}
|
|
7355
|
-
}
|
|
7356
|
-
const documents = [];
|
|
7357
|
-
for (const key of keys) {
|
|
7358
|
-
const stringify = await this.api.select(key, false, tx2);
|
|
7359
|
-
if (!stringify) {
|
|
7360
|
-
continue;
|
|
7380
|
+
documents.push(doc);
|
|
7381
|
+
if (documents.length >= limit) break;
|
|
7361
7382
|
}
|
|
7362
|
-
documents.push(JSON.parse(stringify));
|
|
7363
7383
|
}
|
|
7364
7384
|
return documents;
|
|
7365
7385
|
}, tx);
|
|
@@ -43,9 +43,12 @@ export type DocumentDataplyCondition<V> = {
|
|
|
43
43
|
equal?: Partial<V>;
|
|
44
44
|
notEqual?: Partial<V>;
|
|
45
45
|
like?: Partial<V>;
|
|
46
|
+
or?: Partial<V>[];
|
|
46
47
|
};
|
|
47
48
|
export type DocumentDataplyQuery<T> = {
|
|
48
|
-
[key in keyof T]
|
|
49
|
+
[key in keyof T]?: T[key] | DocumentDataplyCondition<T[key]>;
|
|
50
|
+
} & {
|
|
51
|
+
[key: string]: any;
|
|
49
52
|
};
|
|
50
53
|
export interface DataplyTreeValue<T> {
|
|
51
54
|
k: number;
|
|
@@ -54,13 +57,21 @@ export interface DataplyTreeValue<T> {
|
|
|
54
57
|
/**
|
|
55
58
|
* T가 객체인지 확인하고, 객체라면 하위 키를 재귀적으로 탐색합니다.
|
|
56
59
|
*/
|
|
57
|
-
type
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
|
|
61
|
+
/**
|
|
62
|
+
* T가 객체인지 확인하고, 객체라면 하위 키를 재귀적으로 탐색합니다.
|
|
63
|
+
* Depth 제한을 두어 "Type instantiation is excessively deep and possibly infinite" 에러를 방지합니다.
|
|
64
|
+
*/
|
|
65
|
+
export type DeepFlattenKeys<T, Prefix extends string = "", D extends number = 12> = [
|
|
66
|
+
D
|
|
67
|
+
] extends [0] ? never : T extends Primitive ? (Prefix extends `${infer P}.` ? P : never) : T extends readonly any[] ? ((Prefix extends `${infer P}.` ? P : never) | DeepFlattenKeys<T[number], `${Prefix}${number}.`, Prev[D]>) : T extends object ? {
|
|
68
|
+
[K in keyof T & string]: NonNullable<T[K]> extends Primitive ? `${Prefix}${K}` : `${Prefix}${K}` | DeepFlattenKeys<NonNullable<T[K]>, `${Prefix}${K}.`, Prev[D]>;
|
|
69
|
+
}[keyof T & string] : never;
|
|
60
70
|
/**
|
|
61
71
|
* 경로 문자열(Path)을 기반으로 원본 객체(T)에서 타입을 찾아옵니다.
|
|
72
|
+
* 배열 인덱스 접근 허용 (ex: tags.0)
|
|
62
73
|
*/
|
|
63
|
-
type GetTypeByPath<T, Path extends string> = Path extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? GetTypeByPath<NonNullable<T[Key]>, Rest> : never : Path extends keyof T ? T[Path] : never;
|
|
74
|
+
type GetTypeByPath<T, Path extends string> = T extends readonly (infer U)[] ? Path extends `${infer Key}.${infer Rest}` ? Key extends `${number}` ? GetTypeByPath<U, Rest> : Key extends keyof T ? GetTypeByPath<T[Key], Rest> : never : Path extends `${number}` ? U : Path extends keyof T ? T[Path] : never : Path extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? GetTypeByPath<NonNullable<T[Key]>, Rest> : never : Path extends keyof T ? T[Path] : never;
|
|
64
75
|
export type FinalFlatten<T> = {
|
|
65
76
|
[P in DeepFlattenKeys<T>]: GetTypeByPath<T, P & string>;
|
|
66
77
|
};
|