@atscript/mongo 0.0.22 → 0.0.24
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 +43 -13
- package/dist/index.d.ts +3 -1
- package/dist/index.mjs +43 -13
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -431,9 +431,7 @@ else t.prop(key, (0, __atscript_typescript.defineAnnotatedType)().refTo(val).cop
|
|
|
431
431
|
}
|
|
432
432
|
return def;
|
|
433
433
|
},
|
|
434
|
-
partial: (def, path) =>
|
|
435
|
-
return path !== "" && def.metadata.get("mongo.patch.strategy") === "merge";
|
|
436
|
-
}
|
|
434
|
+
partial: (def, path) => path !== "" && def.metadata.get("mongo.patch.strategy") === "merge"
|
|
437
435
|
});
|
|
438
436
|
}
|
|
439
437
|
/**
|
|
@@ -772,29 +770,61 @@ else {
|
|
|
772
770
|
if (analyzer) index.definition.mappings.fields[fieldName].analyzer = analyzer;
|
|
773
771
|
}
|
|
774
772
|
}
|
|
775
|
-
|
|
776
|
-
|
|
773
|
+
_addFieldToFlatMap(name, def) {
|
|
774
|
+
if (this._flatMap) {
|
|
775
|
+
const existing = this._flatMap.get(name);
|
|
776
|
+
if (existing) {
|
|
777
|
+
const flatUnion = (0, __atscript_typescript.defineAnnotatedType)("union").copyMetadata(existing.metadata).copyMetadata(def.metadata);
|
|
778
|
+
if (existing.__flat_union) existing.type.items.forEach((item) => flatUnion.item(item));
|
|
779
|
+
else flatUnion.item(existing);
|
|
780
|
+
flatUnion.item(def);
|
|
781
|
+
const type = flatUnion.$type;
|
|
782
|
+
type.__flat_union = true;
|
|
783
|
+
this._flatMap.set(name, flatUnion.$type);
|
|
784
|
+
} else this._flatMap.set(name, def);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
_flattenType(def, prefix = "", inComplexTypeOrArray = false) {
|
|
788
|
+
switch (def.type.kind) {
|
|
777
789
|
case "object":
|
|
778
|
-
this.
|
|
779
|
-
const items = Array.from(
|
|
790
|
+
this._addFieldToFlatMap(prefix || "", def);
|
|
791
|
+
const items = Array.from(def.type.props.entries());
|
|
780
792
|
for (const [key, value] of items) this._flattenType(value, prefix ? `${prefix}.${key}` : key, inComplexTypeOrArray);
|
|
781
793
|
break;
|
|
782
794
|
case "array":
|
|
783
|
-
let typeArray =
|
|
795
|
+
let typeArray = def;
|
|
784
796
|
if (!inComplexTypeOrArray) {
|
|
785
|
-
typeArray = (0, __atscript_typescript.defineAnnotatedType)().refTo(
|
|
797
|
+
typeArray = (0, __atscript_typescript.defineAnnotatedType)().refTo(def).copyMetadata(def.metadata).$type;
|
|
786
798
|
typeArray.metadata.set("mongo.__topLevelArray", true);
|
|
787
799
|
}
|
|
788
|
-
this.
|
|
800
|
+
this._addFieldToFlatMap(prefix || "", typeArray);
|
|
801
|
+
if (!(0, __atscript_typescript.isAnnotatedTypeOfPrimitive)(typeArray.type.of)) this._flattenArray(typeArray.type.of, prefix);
|
|
789
802
|
break;
|
|
790
803
|
case "intersection":
|
|
791
804
|
case "tuple":
|
|
792
|
-
case "union": for (const item of
|
|
805
|
+
case "union": for (const item of def.type.items) this._flattenType(item, prefix, true);
|
|
793
806
|
default:
|
|
794
|
-
this.
|
|
807
|
+
this._addFieldToFlatMap(prefix || "", def);
|
|
808
|
+
break;
|
|
809
|
+
}
|
|
810
|
+
if (prefix) this._prepareIndexesForField(prefix, def.metadata);
|
|
811
|
+
}
|
|
812
|
+
_flattenArray(def, name) {
|
|
813
|
+
switch (def.type.kind) {
|
|
814
|
+
case "object":
|
|
815
|
+
const items = Array.from(def.type.props.entries());
|
|
816
|
+
for (const [key, value] of items) this._flattenType(value, name ? `${name}.${key}` : key, true);
|
|
795
817
|
break;
|
|
818
|
+
case "union":
|
|
819
|
+
case "intersection":
|
|
820
|
+
case "tuple":
|
|
821
|
+
for (const item of def.type.items) this._flattenArray(item, name);
|
|
822
|
+
break;
|
|
823
|
+
case "array":
|
|
824
|
+
this._flattenArray(def.type.of, name);
|
|
825
|
+
break;
|
|
826
|
+
default:
|
|
796
827
|
}
|
|
797
|
-
if (prefix) this._prepareIndexesForField(prefix, type.metadata);
|
|
798
828
|
}
|
|
799
829
|
_prepareIndexesForCollection() {
|
|
800
830
|
const typeMeta = this.type.metadata;
|
package/dist/index.d.ts
CHANGED
|
@@ -80,7 +80,9 @@ declare class AsCollection<T extends TAtscriptAnnotatedTypeConstructor> {
|
|
|
80
80
|
protected _addIndexField(type: TPlainIndex['type'], name: string, field: string, weight?: number): void;
|
|
81
81
|
protected _setSearchIndex(type: TSearchIndex['type'], name: string | undefined, definition: TMongoSearchIndexDefinition): void;
|
|
82
82
|
protected _addFieldToSearchIndex(type: TSearchIndex['type'], _name: string | undefined, fieldName: string, analyzer?: string): void;
|
|
83
|
-
protected
|
|
83
|
+
protected _addFieldToFlatMap(name: string, def: TAtscriptAnnotatedType): void;
|
|
84
|
+
protected _flattenType(def: TAtscriptAnnotatedType, prefix?: string, inComplexTypeOrArray?: boolean): void;
|
|
85
|
+
_flattenArray(def: TAtscriptAnnotatedType, name: string): void;
|
|
84
86
|
protected _prepareIndexesForCollection(): void;
|
|
85
87
|
protected _uniqueProps: Set<string>;
|
|
86
88
|
get uniqueProps(): Set<string>;
|
package/dist/index.mjs
CHANGED
|
@@ -407,9 +407,7 @@ else t.prop(key, defineAnnotatedType().refTo(val).copyMetadata(def.metadata).opt
|
|
|
407
407
|
}
|
|
408
408
|
return def;
|
|
409
409
|
},
|
|
410
|
-
partial: (def, path) =>
|
|
411
|
-
return path !== "" && def.metadata.get("mongo.patch.strategy") === "merge";
|
|
412
|
-
}
|
|
410
|
+
partial: (def, path) => path !== "" && def.metadata.get("mongo.patch.strategy") === "merge"
|
|
413
411
|
});
|
|
414
412
|
}
|
|
415
413
|
/**
|
|
@@ -748,29 +746,61 @@ else {
|
|
|
748
746
|
if (analyzer) index.definition.mappings.fields[fieldName].analyzer = analyzer;
|
|
749
747
|
}
|
|
750
748
|
}
|
|
751
|
-
|
|
752
|
-
|
|
749
|
+
_addFieldToFlatMap(name, def) {
|
|
750
|
+
if (this._flatMap) {
|
|
751
|
+
const existing = this._flatMap.get(name);
|
|
752
|
+
if (existing) {
|
|
753
|
+
const flatUnion = defineAnnotatedType("union").copyMetadata(existing.metadata).copyMetadata(def.metadata);
|
|
754
|
+
if (existing.__flat_union) existing.type.items.forEach((item) => flatUnion.item(item));
|
|
755
|
+
else flatUnion.item(existing);
|
|
756
|
+
flatUnion.item(def);
|
|
757
|
+
const type = flatUnion.$type;
|
|
758
|
+
type.__flat_union = true;
|
|
759
|
+
this._flatMap.set(name, flatUnion.$type);
|
|
760
|
+
} else this._flatMap.set(name, def);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
_flattenType(def, prefix = "", inComplexTypeOrArray = false) {
|
|
764
|
+
switch (def.type.kind) {
|
|
753
765
|
case "object":
|
|
754
|
-
this.
|
|
755
|
-
const items = Array.from(
|
|
766
|
+
this._addFieldToFlatMap(prefix || "", def);
|
|
767
|
+
const items = Array.from(def.type.props.entries());
|
|
756
768
|
for (const [key, value] of items) this._flattenType(value, prefix ? `${prefix}.${key}` : key, inComplexTypeOrArray);
|
|
757
769
|
break;
|
|
758
770
|
case "array":
|
|
759
|
-
let typeArray =
|
|
771
|
+
let typeArray = def;
|
|
760
772
|
if (!inComplexTypeOrArray) {
|
|
761
|
-
typeArray = defineAnnotatedType().refTo(
|
|
773
|
+
typeArray = defineAnnotatedType().refTo(def).copyMetadata(def.metadata).$type;
|
|
762
774
|
typeArray.metadata.set("mongo.__topLevelArray", true);
|
|
763
775
|
}
|
|
764
|
-
this.
|
|
776
|
+
this._addFieldToFlatMap(prefix || "", typeArray);
|
|
777
|
+
if (!isAnnotatedTypeOfPrimitive(typeArray.type.of)) this._flattenArray(typeArray.type.of, prefix);
|
|
765
778
|
break;
|
|
766
779
|
case "intersection":
|
|
767
780
|
case "tuple":
|
|
768
|
-
case "union": for (const item of
|
|
781
|
+
case "union": for (const item of def.type.items) this._flattenType(item, prefix, true);
|
|
769
782
|
default:
|
|
770
|
-
this.
|
|
783
|
+
this._addFieldToFlatMap(prefix || "", def);
|
|
784
|
+
break;
|
|
785
|
+
}
|
|
786
|
+
if (prefix) this._prepareIndexesForField(prefix, def.metadata);
|
|
787
|
+
}
|
|
788
|
+
_flattenArray(def, name) {
|
|
789
|
+
switch (def.type.kind) {
|
|
790
|
+
case "object":
|
|
791
|
+
const items = Array.from(def.type.props.entries());
|
|
792
|
+
for (const [key, value] of items) this._flattenType(value, name ? `${name}.${key}` : key, true);
|
|
771
793
|
break;
|
|
794
|
+
case "union":
|
|
795
|
+
case "intersection":
|
|
796
|
+
case "tuple":
|
|
797
|
+
for (const item of def.type.items) this._flattenArray(item, name);
|
|
798
|
+
break;
|
|
799
|
+
case "array":
|
|
800
|
+
this._flattenArray(def.type.of, name);
|
|
801
|
+
break;
|
|
802
|
+
default:
|
|
772
803
|
}
|
|
773
|
-
if (prefix) this._prepareIndexesForField(prefix, type.metadata);
|
|
774
804
|
}
|
|
775
805
|
_prepareIndexesForCollection() {
|
|
776
806
|
const typeMeta = this.type.metadata;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/mongo",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.24",
|
|
4
4
|
"description": "Mongodb plugin for atscript.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"license": "ISC",
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"mongodb": "^6.17.0",
|
|
37
|
-
"@atscript/core": "^0.0.
|
|
38
|
-
"@atscript/typescript": "^0.0.
|
|
37
|
+
"@atscript/core": "^0.0.24",
|
|
38
|
+
"@atscript/typescript": "^0.0.24"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"vitest": "3.2.4"
|