@anteros/core 0.0.23 → 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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@anteros/core",
3
3
  "module": "index.ts",
4
- "version": "0.0.23",
4
+ "version": "0.0.24",
5
5
  "type": "module",
6
6
  "description": "Anteros Core",
7
7
  "private": false,
package/tests/api.test.ts CHANGED
@@ -73,6 +73,56 @@ describe("find", () => {
73
73
  });
74
74
  });
75
75
 
76
+ describe("$limit", () => {
77
+ it("$limit: 0 means no limit (returns all matching docs)", async () => {
78
+ const marker = `limit-zero-${crypto.randomUUID()}`;
79
+ await rest.bulkWrite("items", Array.from({ length: 101 }, (_, i) => ({
80
+ insertOne: { document: { title: marker, count: i } },
81
+ })) as any);
82
+
83
+ const all = await rest.find("items", { $match: { title: marker }, $limit: 0 });
84
+ expect(all.length).toBe(101); // the old 100 cap would have returned 100
85
+
86
+ await rest.db.collection("items").deleteMany({ title: marker });
87
+ });
88
+
89
+ it("accepts $limit above 1000", async () => {
90
+ const marker = `limit-big-${crypto.randomUUID()}`;
91
+ await rest.insertMany("items", [
92
+ { title: marker, count: 1 },
93
+ { title: marker, count: 2 },
94
+ { title: marker, count: 3 },
95
+ ]);
96
+
97
+ const docs = await rest.find("items", { $match: { title: marker }, $limit: 5000 });
98
+ expect(docs.length).toBe(3);
99
+
100
+ await rest.db.collection("items").deleteMany({ title: marker });
101
+ });
102
+
103
+ it("defaults to $limit 100", async () => {
104
+ const marker = `limit-default-${crypto.randomUUID()}`;
105
+ await rest.bulkWrite("items", Array.from({ length: 120 }, (_, i) => ({
106
+ insertOne: { document: { title: marker, count: i } },
107
+ })) as any);
108
+
109
+ const docs = await rest.find("items", { $match: { title: marker } });
110
+ expect(docs.length).toBe(100);
111
+
112
+ await rest.db.collection("items").deleteMany({ title: marker });
113
+ });
114
+
115
+ it("rejects negative $limit with INVALID_LIMIT", async () => {
116
+ const err: any = await rest.find("items", { $limit: -1 }).then(() => null, (e) => e);
117
+ expect(err?.code).toBe("INVALID_LIMIT");
118
+ });
119
+
120
+ it("rejects non-integer $limit with INVALID_LIMIT", async () => {
121
+ const err: any = await rest.find("items", { $limit: 1.5 }).then(() => null, (e) => e);
122
+ expect(err?.code).toBe("INVALID_LIMIT");
123
+ });
124
+ });
125
+
76
126
  describe("findOne", () => {
77
127
  it("returns single doc by _id", async () => {
78
128
  const doc = await rest.insertOne("items", { title: "single" });
package/utils/func.ts CHANGED
@@ -748,18 +748,20 @@ function buildPipeline(p: FindOptions, options?: {
748
748
  })
749
749
  }
750
750
 
751
- // $limit — Faille 14: must be a safe integer in (0, MAX_LIMIT]; 0 would mean "no limit"
752
- const MAX_LIMIT = 1000;
751
+ // $limit — 0 means "no limit" (the $limit stage is omitted);
752
+ // any positive safe integer is allowed (no 1000 cap)
753
753
  p.$limit = p?.$limit ?? 100
754
- if (!Number.isSafeInteger(p.$limit) || p.$limit <= 0 || p.$limit > MAX_LIMIT) {
755
- throw new AppError(`Invalid $limit (expected an integer between 1 and ${MAX_LIMIT})`, {
754
+ if (!Number.isSafeInteger(p.$limit) || p.$limit < 0) {
755
+ throw new AppError(`Invalid $limit (expected a non-negative integer; 0 = no limit)`, {
756
756
  code: 'INVALID_LIMIT',
757
757
  status: 400
758
758
  });
759
759
  }
760
- pipeline.push({
761
- $limit: p.$limit
762
- })
760
+ if (p.$limit > 0) {
761
+ pipeline.push({
762
+ $limit: p.$limit
763
+ })
764
+ }
763
765
 
764
766
  // $include
765
767
  if (p?.$include && Array.isArray(p?.$include)) {