@atscript/mongo 0.1.8 → 0.1.9
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 +5 -64
- package/dist/index.d.ts +0 -3
- package/dist/index.mjs +6 -65
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -773,68 +773,6 @@ else {
|
|
|
773
773
|
if (analyzer) index.definition.mappings.fields[fieldName].analyzer = analyzer;
|
|
774
774
|
}
|
|
775
775
|
}
|
|
776
|
-
_addFieldToFlatMap(name, def) {
|
|
777
|
-
if (this._flatMap) {
|
|
778
|
-
const existing = this._flatMap.get(name);
|
|
779
|
-
if (existing) {
|
|
780
|
-
const flatUnion = (0, __atscript_typescript_utils.defineAnnotatedType)("union").copyMetadata(existing.metadata).copyMetadata(def.metadata);
|
|
781
|
-
if (existing.__flat_union) existing.type.items.forEach((item) => flatUnion.item(item));
|
|
782
|
-
else flatUnion.item(existing);
|
|
783
|
-
flatUnion.item(def);
|
|
784
|
-
const type = flatUnion.$type;
|
|
785
|
-
type.__flat_union = true;
|
|
786
|
-
this._flatMap.set(name, flatUnion.$type);
|
|
787
|
-
} else this._flatMap.set(name, def);
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
_flattenType(def, prefix = "", inComplexTypeOrArray = false) {
|
|
791
|
-
switch (def.type.kind) {
|
|
792
|
-
case "object":
|
|
793
|
-
this._addFieldToFlatMap(prefix || "", def);
|
|
794
|
-
const items = Array.from(def.type.props.entries());
|
|
795
|
-
for (const [key, value] of items) {
|
|
796
|
-
if ((0, __atscript_typescript_utils.isPhantomType)(value)) continue;
|
|
797
|
-
this._flattenType(value, prefix ? `${prefix}.${key}` : key, inComplexTypeOrArray);
|
|
798
|
-
}
|
|
799
|
-
break;
|
|
800
|
-
case "array":
|
|
801
|
-
let typeArray = def;
|
|
802
|
-
if (!inComplexTypeOrArray) {
|
|
803
|
-
typeArray = (0, __atscript_typescript_utils.defineAnnotatedType)().refTo(def).copyMetadata(def.metadata).$type;
|
|
804
|
-
typeArray.metadata.set("mongo.__topLevelArray", true);
|
|
805
|
-
}
|
|
806
|
-
this._addFieldToFlatMap(prefix || "", typeArray);
|
|
807
|
-
if (!(0, __atscript_typescript_utils.isAnnotatedTypeOfPrimitive)(typeArray.type.of)) this._flattenArray(typeArray.type.of, prefix);
|
|
808
|
-
break;
|
|
809
|
-
case "intersection":
|
|
810
|
-
case "tuple":
|
|
811
|
-
case "union": for (const item of def.type.items) this._flattenType(item, prefix, true);
|
|
812
|
-
default:
|
|
813
|
-
this._addFieldToFlatMap(prefix || "", def);
|
|
814
|
-
break;
|
|
815
|
-
}
|
|
816
|
-
if (prefix) this._prepareIndexesForField(prefix, def.metadata);
|
|
817
|
-
}
|
|
818
|
-
_flattenArray(def, name) {
|
|
819
|
-
switch (def.type.kind) {
|
|
820
|
-
case "object":
|
|
821
|
-
const items = Array.from(def.type.props.entries());
|
|
822
|
-
for (const [key, value] of items) {
|
|
823
|
-
if ((0, __atscript_typescript_utils.isPhantomType)(value)) continue;
|
|
824
|
-
this._flattenType(value, name ? `${name}.${key}` : key, true);
|
|
825
|
-
}
|
|
826
|
-
break;
|
|
827
|
-
case "union":
|
|
828
|
-
case "intersection":
|
|
829
|
-
case "tuple":
|
|
830
|
-
for (const item of def.type.items) this._flattenArray(item, name);
|
|
831
|
-
break;
|
|
832
|
-
case "array":
|
|
833
|
-
this._flattenArray(def.type.of, name);
|
|
834
|
-
break;
|
|
835
|
-
default:
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
776
|
_prepareIndexesForCollection() {
|
|
839
777
|
const typeMeta = this.type.metadata;
|
|
840
778
|
const dynamicText = typeMeta.get("mongo.search.dynamic");
|
|
@@ -882,9 +820,12 @@ else flatUnion.item(existing);
|
|
|
882
820
|
}
|
|
883
821
|
_flatten() {
|
|
884
822
|
if (!this._flatMap) {
|
|
885
|
-
this._flatMap = new Map();
|
|
886
823
|
this._prepareIndexesForCollection();
|
|
887
|
-
this.
|
|
824
|
+
this._flatMap = (0, __atscript_typescript_utils.flattenAnnotatedType)(this.type, {
|
|
825
|
+
topLevelArrayTag: "mongo.__topLevelArray",
|
|
826
|
+
excludePhantomTypes: true,
|
|
827
|
+
onField: (path, _type, metadata) => this._prepareIndexesForField(path, metadata)
|
|
828
|
+
});
|
|
888
829
|
this._finalizeIndexesForCollection();
|
|
889
830
|
}
|
|
890
831
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -86,9 +86,6 @@ declare class AsCollection<T extends TAtscriptAnnotatedType = TAtscriptAnnotated
|
|
|
86
86
|
protected _addIndexField(type: TPlainIndex['type'], name: string, field: string, weight?: number): void;
|
|
87
87
|
protected _setSearchIndex(type: TSearchIndex['type'], name: string | undefined, definition: TMongoSearchIndexDefinition): void;
|
|
88
88
|
protected _addFieldToSearchIndex(type: TSearchIndex['type'], _name: string | undefined, fieldName: string, analyzer?: string): void;
|
|
89
|
-
protected _addFieldToFlatMap(name: string, def: TAtscriptAnnotatedType): void;
|
|
90
|
-
protected _flattenType(def: TAtscriptAnnotatedType, prefix?: string, inComplexTypeOrArray?: boolean): void;
|
|
91
|
-
_flattenArray(def: TAtscriptAnnotatedType, name: string): void;
|
|
92
89
|
protected _prepareIndexesForCollection(): void;
|
|
93
90
|
protected _uniqueProps: Set<string>;
|
|
94
91
|
get uniqueProps(): Set<string>;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AnnotationSpec, isArray, isInterface, isPrimitive, isRef, isStructure } from "@atscript/core";
|
|
2
|
-
import { defineAnnotatedType, isAnnotatedType, isAnnotatedTypeOfPrimitive
|
|
2
|
+
import { defineAnnotatedType, flattenAnnotatedType, isAnnotatedType, isAnnotatedTypeOfPrimitive } from "@atscript/typescript/utils";
|
|
3
3
|
import { MongoClient, ObjectId } from "mongodb";
|
|
4
4
|
|
|
5
5
|
//#region packages/mongo/src/plugin/primitives.ts
|
|
@@ -749,68 +749,6 @@ else {
|
|
|
749
749
|
if (analyzer) index.definition.mappings.fields[fieldName].analyzer = analyzer;
|
|
750
750
|
}
|
|
751
751
|
}
|
|
752
|
-
_addFieldToFlatMap(name, def) {
|
|
753
|
-
if (this._flatMap) {
|
|
754
|
-
const existing = this._flatMap.get(name);
|
|
755
|
-
if (existing) {
|
|
756
|
-
const flatUnion = defineAnnotatedType("union").copyMetadata(existing.metadata).copyMetadata(def.metadata);
|
|
757
|
-
if (existing.__flat_union) existing.type.items.forEach((item) => flatUnion.item(item));
|
|
758
|
-
else flatUnion.item(existing);
|
|
759
|
-
flatUnion.item(def);
|
|
760
|
-
const type = flatUnion.$type;
|
|
761
|
-
type.__flat_union = true;
|
|
762
|
-
this._flatMap.set(name, flatUnion.$type);
|
|
763
|
-
} else this._flatMap.set(name, def);
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
_flattenType(def, prefix = "", inComplexTypeOrArray = false) {
|
|
767
|
-
switch (def.type.kind) {
|
|
768
|
-
case "object":
|
|
769
|
-
this._addFieldToFlatMap(prefix || "", def);
|
|
770
|
-
const items = Array.from(def.type.props.entries());
|
|
771
|
-
for (const [key, value] of items) {
|
|
772
|
-
if (isPhantomType(value)) continue;
|
|
773
|
-
this._flattenType(value, prefix ? `${prefix}.${key}` : key, inComplexTypeOrArray);
|
|
774
|
-
}
|
|
775
|
-
break;
|
|
776
|
-
case "array":
|
|
777
|
-
let typeArray = def;
|
|
778
|
-
if (!inComplexTypeOrArray) {
|
|
779
|
-
typeArray = defineAnnotatedType().refTo(def).copyMetadata(def.metadata).$type;
|
|
780
|
-
typeArray.metadata.set("mongo.__topLevelArray", true);
|
|
781
|
-
}
|
|
782
|
-
this._addFieldToFlatMap(prefix || "", typeArray);
|
|
783
|
-
if (!isAnnotatedTypeOfPrimitive(typeArray.type.of)) this._flattenArray(typeArray.type.of, prefix);
|
|
784
|
-
break;
|
|
785
|
-
case "intersection":
|
|
786
|
-
case "tuple":
|
|
787
|
-
case "union": for (const item of def.type.items) this._flattenType(item, prefix, true);
|
|
788
|
-
default:
|
|
789
|
-
this._addFieldToFlatMap(prefix || "", def);
|
|
790
|
-
break;
|
|
791
|
-
}
|
|
792
|
-
if (prefix) this._prepareIndexesForField(prefix, def.metadata);
|
|
793
|
-
}
|
|
794
|
-
_flattenArray(def, name) {
|
|
795
|
-
switch (def.type.kind) {
|
|
796
|
-
case "object":
|
|
797
|
-
const items = Array.from(def.type.props.entries());
|
|
798
|
-
for (const [key, value] of items) {
|
|
799
|
-
if (isPhantomType(value)) continue;
|
|
800
|
-
this._flattenType(value, name ? `${name}.${key}` : key, true);
|
|
801
|
-
}
|
|
802
|
-
break;
|
|
803
|
-
case "union":
|
|
804
|
-
case "intersection":
|
|
805
|
-
case "tuple":
|
|
806
|
-
for (const item of def.type.items) this._flattenArray(item, name);
|
|
807
|
-
break;
|
|
808
|
-
case "array":
|
|
809
|
-
this._flattenArray(def.type.of, name);
|
|
810
|
-
break;
|
|
811
|
-
default:
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
752
|
_prepareIndexesForCollection() {
|
|
815
753
|
const typeMeta = this.type.metadata;
|
|
816
754
|
const dynamicText = typeMeta.get("mongo.search.dynamic");
|
|
@@ -858,9 +796,12 @@ else flatUnion.item(existing);
|
|
|
858
796
|
}
|
|
859
797
|
_flatten() {
|
|
860
798
|
if (!this._flatMap) {
|
|
861
|
-
this._flatMap = new Map();
|
|
862
799
|
this._prepareIndexesForCollection();
|
|
863
|
-
this.
|
|
800
|
+
this._flatMap = flattenAnnotatedType(this.type, {
|
|
801
|
+
topLevelArrayTag: "mongo.__topLevelArray",
|
|
802
|
+
excludePhantomTypes: true,
|
|
803
|
+
onField: (path, _type, metadata) => this._prepareIndexesForField(path, metadata)
|
|
804
|
+
});
|
|
864
805
|
this._finalizeIndexesForCollection();
|
|
865
806
|
}
|
|
866
807
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/mongo",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
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.1.
|
|
38
|
-
"@atscript/typescript": "^0.1.
|
|
37
|
+
"@atscript/core": "^0.1.9",
|
|
38
|
+
"@atscript/typescript": "^0.1.9"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"vitest": "3.2.4"
|