@atscript/mongo 0.0.29 → 0.0.30

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 CHANGED
@@ -23,7 +23,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
23
23
 
24
24
  //#endregion
25
25
  const __atscript_core = __toESM(require("@atscript/core"));
26
- const __atscript_typescript = __toESM(require("@atscript/typescript"));
26
+ const __atscript_typescript_utils = __toESM(require("@atscript/typescript/utils"));
27
27
  const mongodb = __toESM(require("mongodb"));
28
28
 
29
29
  //#region packages/mongo/src/plugin/primitives.ts
@@ -404,30 +404,30 @@ var CollectionPatcher = class CollectionPatcher {
404
404
  plugins: [validateMongoIdPlugin, validateMongoUniqueArrayItemsPlugin],
405
405
  replace: (def, path) => {
406
406
  if (path === "" && def.type.kind === "object") {
407
- const obj = (0, __atscript_typescript.defineAnnotatedType)("object").copyMetadata(def.metadata);
408
- for (const [prop, type] of def.type.props.entries()) obj.prop(prop, (0, __atscript_typescript.defineAnnotatedType)().refTo(type).copyMetadata(type.metadata).optional(prop !== "_id").$type);
407
+ const obj = (0, __atscript_typescript_utils.defineAnnotatedType)("object").copyMetadata(def.metadata);
408
+ for (const [prop, type] of def.type.props.entries()) obj.prop(prop, (0, __atscript_typescript_utils.defineAnnotatedType)().refTo(type).copyMetadata(type.metadata).optional(prop !== "_id").$type);
409
409
  return obj.$type;
410
410
  }
411
411
  if (def.type.kind === "array" && collection.flatMap.get(path)?.metadata.get("mongo.__topLevelArray") && !def.metadata.has("mongo.__patchArrayValue")) {
412
412
  const defArray = def;
413
413
  const mergeStrategy = defArray.metadata.get("mongo.patch.strategy") === "merge";
414
414
  function getPatchType() {
415
- const isPrimitive$1 = (0, __atscript_typescript.isAnnotatedTypeOfPrimitive)(defArray.type.of);
416
- if (isPrimitive$1) return (0, __atscript_typescript.defineAnnotatedType)().refTo(def).copyMetadata(def.metadata).annotate("mongo.__patchArrayValue").optional().$type;
415
+ const isPrimitive$1 = (0, __atscript_typescript_utils.isAnnotatedTypeOfPrimitive)(defArray.type.of);
416
+ if (isPrimitive$1) return (0, __atscript_typescript_utils.defineAnnotatedType)().refTo(def).copyMetadata(def.metadata).annotate("mongo.__patchArrayValue").optional().$type;
417
417
  if (defArray.type.of.type.kind === "object") {
418
418
  const objType = defArray.type.of.type;
419
- const t = (0, __atscript_typescript.defineAnnotatedType)("object").copyMetadata(defArray.type.of.metadata);
419
+ const t = (0, __atscript_typescript_utils.defineAnnotatedType)("object").copyMetadata(defArray.type.of.metadata);
420
420
  const keyProps = CollectionPatcher.getKeyProps(defArray);
421
- for (const [key, val] of objType.props.entries()) if (keyProps.size) if (keyProps.has(key)) t.prop(key, (0, __atscript_typescript.defineAnnotatedType)().refTo(val).copyMetadata(def.metadata).$type);
422
- else t.prop(key, (0, __atscript_typescript.defineAnnotatedType)().refTo(val).copyMetadata(def.metadata).optional().$type);
423
- else t.prop(key, (0, __atscript_typescript.defineAnnotatedType)().refTo(val).copyMetadata(def.metadata).optional(!!val.optional).$type);
424
- return (0, __atscript_typescript.defineAnnotatedType)("array").of(t.$type).copyMetadata(def.metadata).annotate("mongo.__patchArrayValue").optional().$type;
421
+ for (const [key, val] of objType.props.entries()) if (keyProps.size) if (keyProps.has(key)) t.prop(key, (0, __atscript_typescript_utils.defineAnnotatedType)().refTo(val).copyMetadata(def.metadata).$type);
422
+ else t.prop(key, (0, __atscript_typescript_utils.defineAnnotatedType)().refTo(val).copyMetadata(def.metadata).optional().$type);
423
+ else t.prop(key, (0, __atscript_typescript_utils.defineAnnotatedType)().refTo(val).copyMetadata(def.metadata).optional(!!val.optional).$type);
424
+ return (0, __atscript_typescript_utils.defineAnnotatedType)("array").of(t.$type).copyMetadata(def.metadata).annotate("mongo.__patchArrayValue").optional().$type;
425
425
  }
426
426
  return undefined;
427
427
  }
428
- const fullType = (0, __atscript_typescript.defineAnnotatedType)().refTo(def).copyMetadata(def.metadata).annotate("mongo.__patchArrayValue").optional().$type;
428
+ const fullType = (0, __atscript_typescript_utils.defineAnnotatedType)().refTo(def).copyMetadata(def.metadata).annotate("mongo.__patchArrayValue").optional().$type;
429
429
  const patchType = getPatchType();
430
- return patchType ? (0, __atscript_typescript.defineAnnotatedType)("object").prop("$replace", fullType).prop("$insert", fullType).prop("$upsert", fullType).prop("$update", mergeStrategy ? patchType : fullType).prop("$remove", patchType).optional().$type : (0, __atscript_typescript.defineAnnotatedType)("object").prop("$replace", fullType).prop("$insert", fullType).optional().$type;
430
+ return patchType ? (0, __atscript_typescript_utils.defineAnnotatedType)("object").prop("$replace", fullType).prop("$insert", fullType).prop("$upsert", fullType).prop("$update", mergeStrategy ? patchType : fullType).prop("$remove", patchType).optional().$type : (0, __atscript_typescript_utils.defineAnnotatedType)("object").prop("$replace", fullType).prop("$insert", fullType).optional().$type;
431
431
  }
432
432
  return def;
433
433
  },
@@ -774,7 +774,7 @@ else {
774
774
  if (this._flatMap) {
775
775
  const existing = this._flatMap.get(name);
776
776
  if (existing) {
777
- const flatUnion = (0, __atscript_typescript.defineAnnotatedType)("union").copyMetadata(existing.metadata).copyMetadata(def.metadata);
777
+ const flatUnion = (0, __atscript_typescript_utils.defineAnnotatedType)("union").copyMetadata(existing.metadata).copyMetadata(def.metadata);
778
778
  if (existing.__flat_union) existing.type.items.forEach((item) => flatUnion.item(item));
779
779
  else flatUnion.item(existing);
780
780
  flatUnion.item(def);
@@ -794,11 +794,11 @@ else flatUnion.item(existing);
794
794
  case "array":
795
795
  let typeArray = def;
796
796
  if (!inComplexTypeOrArray) {
797
- typeArray = (0, __atscript_typescript.defineAnnotatedType)().refTo(def).copyMetadata(def.metadata).$type;
797
+ typeArray = (0, __atscript_typescript_utils.defineAnnotatedType)().refTo(def).copyMetadata(def.metadata).$type;
798
798
  typeArray.metadata.set("mongo.__topLevelArray", true);
799
799
  }
800
800
  this._addFieldToFlatMap(prefix || "", typeArray);
801
- if (!(0, __atscript_typescript.isAnnotatedTypeOfPrimitive)(typeArray.type.of)) this._flattenArray(typeArray.type.of, prefix);
801
+ if (!(0, __atscript_typescript_utils.isAnnotatedTypeOfPrimitive)(typeArray.type.of)) this._flattenArray(typeArray.type.of, prefix);
802
802
  break;
803
803
  case "intersection":
804
804
  case "tuple":
@@ -1072,7 +1072,7 @@ else if (this.idType !== "objectId") throw new Error("Missing \"_id\" field");
1072
1072
  this._indexes = new Map();
1073
1073
  this._vectorFilters = new Map();
1074
1074
  this._uniqueProps = new Set();
1075
- if (!(0, __atscript_typescript.isAnnotatedType)(_type)) throw new Error("Atscript Annotated Type expected");
1075
+ if (!(0, __atscript_typescript_utils.isAnnotatedType)(_type)) throw new Error("Atscript Annotated Type expected");
1076
1076
  const name = _type.metadata.get("mongo.collection");
1077
1077
  if (!name) throw new Error("@mongo.collection annotation expected with collection name");
1078
1078
  if (_type.type.kind !== "object") throw new Error("Mongo collection must be an object type");
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { TAtscriptPlugin } from '@atscript/core';
2
2
  import * as mongodb from 'mongodb';
3
3
  import { MongoClient, Collection, ObjectId, InsertOneOptions, ReplaceOptions, UpdateOptions, OptionalUnlessRequiredId, Filter, WithoutId } from 'mongodb';
4
- import { TAtscriptAnnotatedTypeConstructor, TAtscriptAnnotatedType, TAtscriptTypeObject, TMetadataMap } from '@atscript/typescript';
4
+ import * as _atscript_typescript_utils from '@atscript/typescript/utils';
5
+ import { TAtscriptAnnotatedTypeConstructor, Validator, TAtscriptAnnotatedType, TAtscriptTypeObject, TMetadataMap } from '@atscript/typescript/utils';
5
6
 
6
7
  declare const MongoPlugin: () => TAtscriptPlugin;
7
8
 
@@ -74,7 +75,7 @@ declare class AsCollection<T extends TAtscriptAnnotatedTypeConstructor> {
74
75
  * @returns {Validator} The corresponding validator instance.
75
76
  * @throws {Error} If an unknown purpose is provided.
76
77
  */
77
- getValidator(purpose: TValidatorPurpose): any;
78
+ getValidator(purpose: TValidatorPurpose): Validator<T> | undefined;
78
79
  get type(): TAtscriptAnnotatedType<TAtscriptTypeObject>;
79
80
  get indexes(): Map<string, TIndex>;
80
81
  protected _addIndexField(type: TPlainIndex['type'], name: string, field: string, weight?: number): void;
@@ -92,7 +93,7 @@ declare class AsCollection<T extends TAtscriptAnnotatedTypeConstructor> {
92
93
  protected _searchIndexesMap?: Map<string, TIndex>;
93
94
  getSearchIndexes(): Map<string, TIndex>;
94
95
  getSearchIndex(name?: string): TIndex | undefined;
95
- get flatMap(): Map<string, TAtscriptAnnotatedType>;
96
+ get flatMap(): Map<string, TAtscriptAnnotatedType<_atscript_typescript_utils.TAtscriptTypeDef>>;
96
97
  syncIndexes(): Promise<void>;
97
98
  insert(payload: (Omit<InstanceType<T>, '_id'> & {
98
99
  _id?: InstanceType<T>['_id'] | ObjectId;
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 } from "@atscript/typescript";
2
+ import { defineAnnotatedType, isAnnotatedType, isAnnotatedTypeOfPrimitive } from "@atscript/typescript/utils";
3
3
  import { MongoClient, ObjectId } from "mongodb";
4
4
 
5
5
  //#region packages/mongo/src/plugin/primitives.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/mongo",
3
- "version": "0.0.29",
3
+ "version": "0.0.30",
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.29",
38
- "@atscript/typescript": "^0.0.29"
37
+ "@atscript/core": "^0.0.30",
38
+ "@atscript/typescript": "^0.0.30"
39
39
  },
40
40
  "devDependencies": {
41
41
  "vitest": "3.2.4"