@mercury25/aggregator 1.0.0

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.
Files changed (85) hide show
  1. package/dist/aggregate.d.ts +7 -0
  2. package/dist/aggregate.d.ts.map +1 -0
  3. package/dist/aggregate.js +46 -0
  4. package/dist/aggregate.js.map +1 -0
  5. package/dist/buildPipeline.d.ts +4 -0
  6. package/dist/buildPipeline.d.ts.map +1 -0
  7. package/dist/buildPipeline.js +42 -0
  8. package/dist/buildPipeline.js.map +1 -0
  9. package/dist/docs.d.ts +126 -0
  10. package/dist/docs.d.ts.map +1 -0
  11. package/dist/docs.js +123 -0
  12. package/dist/docs.js.map +1 -0
  13. package/dist/errors.d.ts +5 -0
  14. package/dist/errors.d.ts.map +1 -0
  15. package/dist/errors.js +16 -0
  16. package/dist/errors.js.map +1 -0
  17. package/dist/index.d.ts +6 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +5 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/inputSchema.d.ts +118 -0
  22. package/dist/inputSchema.d.ts.map +1 -0
  23. package/dist/inputSchema.js +44 -0
  24. package/dist/inputSchema.js.map +1 -0
  25. package/dist/pipeline/createGroups.d.ts +4 -0
  26. package/dist/pipeline/createGroups.d.ts.map +1 -0
  27. package/dist/pipeline/createGroups.js +61 -0
  28. package/dist/pipeline/createGroups.js.map +1 -0
  29. package/dist/pipeline/createProjects.d.ts +3 -0
  30. package/dist/pipeline/createProjects.d.ts.map +1 -0
  31. package/dist/pipeline/createProjects.js +84 -0
  32. package/dist/pipeline/createProjects.js.map +1 -0
  33. package/dist/pipeline/createSorts.d.ts +4 -0
  34. package/dist/pipeline/createSorts.d.ts.map +1 -0
  35. package/dist/pipeline/createSorts.js +141 -0
  36. package/dist/pipeline/createSorts.js.map +1 -0
  37. package/dist/pipeline/filters/conditionSchemas.d.ts +286 -0
  38. package/dist/pipeline/filters/conditionSchemas.d.ts.map +1 -0
  39. package/dist/pipeline/filters/conditionSchemas.js +57 -0
  40. package/dist/pipeline/filters/conditionSchemas.js.map +1 -0
  41. package/dist/pipeline/filters/conditions.d.ts +8 -0
  42. package/dist/pipeline/filters/conditions.d.ts.map +1 -0
  43. package/dist/pipeline/filters/conditions.js +673 -0
  44. package/dist/pipeline/filters/conditions.js.map +1 -0
  45. package/dist/pipeline/filters/createFilters.d.ts +4 -0
  46. package/dist/pipeline/filters/createFilters.d.ts.map +1 -0
  47. package/dist/pipeline/filters/createFilters.js +107 -0
  48. package/dist/pipeline/filters/createFilters.js.map +1 -0
  49. package/dist/pipeline/verifyCreateAndSort.d.ts +3 -0
  50. package/dist/pipeline/verifyCreateAndSort.d.ts.map +1 -0
  51. package/dist/pipeline/verifyCreateAndSort.js +70 -0
  52. package/dist/pipeline/verifyCreateAndSort.js.map +1 -0
  53. package/dist/pipeline/verifyGroup.d.ts +3 -0
  54. package/dist/pipeline/verifyGroup.d.ts.map +1 -0
  55. package/dist/pipeline/verifyGroup.js +40 -0
  56. package/dist/pipeline/verifyGroup.js.map +1 -0
  57. package/dist/pipeline/verifyProject.d.ts +2 -0
  58. package/dist/pipeline/verifyProject.d.ts.map +1 -0
  59. package/dist/pipeline/verifyProject.js +19 -0
  60. package/dist/pipeline/verifyProject.js.map +1 -0
  61. package/dist/types.d.ts +51 -0
  62. package/dist/types.d.ts.map +1 -0
  63. package/dist/types.js +2 -0
  64. package/dist/types.js.map +1 -0
  65. package/dist/util/dayOfWeekMap.d.ts +11 -0
  66. package/dist/util/dayOfWeekMap.d.ts.map +1 -0
  67. package/dist/util/dayOfWeekMap.js +10 -0
  68. package/dist/util/dayOfWeekMap.js.map +1 -0
  69. package/dist/util/isIsoDateString.d.ts +2 -0
  70. package/dist/util/isIsoDateString.d.ts.map +1 -0
  71. package/dist/util/isIsoDateString.js +9 -0
  72. package/dist/util/isIsoDateString.js.map +1 -0
  73. package/dist/util/isObject.d.ts +2 -0
  74. package/dist/util/isObject.d.ts.map +1 -0
  75. package/dist/util/isObject.js +7 -0
  76. package/dist/util/isObject.js.map +1 -0
  77. package/dist/util/monthMap.d.ts +16 -0
  78. package/dist/util/monthMap.d.ts.map +1 -0
  79. package/dist/util/monthMap.js +15 -0
  80. package/dist/util/monthMap.js.map +1 -0
  81. package/dist/util/numberValidators.d.ts +4 -0
  82. package/dist/util/numberValidators.d.ts.map +1 -0
  83. package/dist/util/numberValidators.js +10 -0
  84. package/dist/util/numberValidators.js.map +1 -0
  85. package/package.json +49 -0
@@ -0,0 +1,7 @@
1
+ import type { Model } from "mongoose";
2
+ import type { AggregateResult, AggregatorInput } from "./types.js";
3
+ export type AggregateArgs = AggregatorInput & {
4
+ model: Model<unknown>;
5
+ };
6
+ export declare const aggregate: (args: AggregateArgs) => Promise<AggregateResult>;
7
+ //# sourceMappingURL=aggregate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aggregate.d.ts","sourceRoot":"","sources":["../src/aggregate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAiB,MAAM,UAAU,CAAC;AAErD,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EAGhB,MAAM,YAAY,CAAC;AAKpB,MAAM,MAAM,aAAa,GAAG,eAAe,GAAG;IAC5C,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;CACvB,CAAC;AAkCF,eAAO,MAAM,SAAS,GAAU,MAAM,aAAa,KAAG,OAAO,CAAC,eAAe,CA+B5E,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { MongoServerError } from "mongodb";
2
+ import { aggregatorInputSchema } from "./inputSchema.js";
3
+ import { buildPipeline } from "./buildPipeline.js";
4
+ import { AggregatorError } from "./errors.js";
5
+ const formatListResult = (aggregationResult, pageNumber, pageSize, removePagination, pipeline) => {
6
+ const matches = aggregationResult?.[0]?.count?.[0]?.count ?? 0;
7
+ const records = aggregationResult?.[0]?.records ?? [];
8
+ return {
9
+ matches,
10
+ count: records.length,
11
+ pageNumber: removePagination ? 1 : pageNumber,
12
+ pageSize: removePagination ? matches : pageSize,
13
+ totalPages: removePagination ? 1 : Math.ceil(matches / pageSize),
14
+ remainingInPages: removePagination ? 0 : Math.max(0, matches - pageSize),
15
+ records: records,
16
+ pipeline,
17
+ };
18
+ };
19
+ const formatGroupResult = (aggregationResult, pipeline) => {
20
+ return {
21
+ groups: aggregationResult,
22
+ pipeline,
23
+ };
24
+ };
25
+ export const aggregate = async (args) => {
26
+ const { model, ...input } = args;
27
+ const parsed = aggregatorInputSchema.parse(input);
28
+ const pipeline = buildPipeline(parsed);
29
+ try {
30
+ const aggregationResult = await model.aggregate(pipeline, { allowDiskUse: true });
31
+ if (parsed.type === "group") {
32
+ return formatGroupResult(aggregationResult, pipeline);
33
+ }
34
+ return formatListResult(aggregationResult, parsed.pageNumber, parsed.pageSize, parsed.removePagination, pipeline);
35
+ }
36
+ catch (error) {
37
+ if (error instanceof MongoServerError) {
38
+ if (error.codeName === "QueryExceededMemoryLimitNoDiskUseAllowed") {
39
+ throw new AggregatorError("Query too large. Please reduce the date range.");
40
+ }
41
+ throw new AggregatorError(`MongoDB error: ${error.message}`);
42
+ }
43
+ throw error;
44
+ }
45
+ };
46
+ //# sourceMappingURL=aggregate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aggregate.js","sourceRoot":"","sources":["../src/aggregate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAO3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAM9C,MAAM,gBAAgB,GAAG,CACvB,iBAAmF,EACnF,UAAkB,EAClB,QAAgB,EAChB,gBAAyB,EACzB,QAAyB,EACJ,EAAE;IACvB,MAAM,OAAO,GAAG,iBAAiB,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE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AI,KAAK,OAAO,EAAE,CAAC;YAC5B,OAAO,iBAAiB,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;QACxD,CAAC;QAED,OAAO,gBAAgB,CACrB,iBAAiB,EACjB,MAAM,CAAC,UAAU,EACjB,MAAM,CAAC,QAAQ,EACf,MAAM,CAAC,gBAAgB,EACvB,QAAQ,CACT,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,gBAAgB,EAAE,CAAC;YACtC,IAAI,KAAK,CAAC,QAAQ,KAAK,0CAA0C,EAAE,CAAC;gBAClE,MAAM,IAAI,eAAe,CAAC,gDAAgD,CAAC,CAAC;YAC9E,CAAC;YAED,MAAM,IAAI,eAAe,CAAC,kBAAkB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QAC/D,CAAC;QAED,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { PipelineStage } from "mongoose";
2
+ import type { AggregatorInput } from "./types.js";
3
+ export declare const buildPipeline: (input: AggregatorInput) => PipelineStage[];
4
+ //# sourceMappingURL=buildPipeline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildPipeline.d.ts","sourceRoot":"","sources":["../src/buildPipeline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AASlD,eAAO,MAAM,aAAa,GAAI,OAAO,eAAe,KAAG,aAAa,EAuDnE,CAAC"}
@@ -0,0 +1,42 @@
1
+ import { aggregatorInputSchema } from "./inputSchema.js";
2
+ import { createFilters } from "./pipeline/filters/createFilters.js";
3
+ import { createProjects } from "./pipeline/createProjects.js";
4
+ import { verifyProject } from "./pipeline/verifyProject.js";
5
+ import { verifyCreateAndSort } from "./pipeline/verifyCreateAndSort.js";
6
+ import { createSorts } from "./pipeline/createSorts.js";
7
+ import { verifyGroup } from "./pipeline/verifyGroup.js";
8
+ import { createGroups } from "./pipeline/createGroups.js";
9
+ export const buildPipeline = (input) => {
10
+ const parsed = aggregatorInputSchema.parse(input);
11
+ const { fieldShapes, type, project, filter, createAndSort, pageNumber, pageSize, removePagination, groups, } = parsed;
12
+ const allowedFieldStrings = Object.keys(fieldShapes);
13
+ const pipeline = [];
14
+ pipeline.push(createFilters(filter, allowedFieldStrings, fieldShapes));
15
+ if (type === "list") {
16
+ verifyCreateAndSort(createAndSort, allowedFieldStrings, fieldShapes);
17
+ const projectVerified = verifyProject(project, allowedFieldStrings);
18
+ pipeline.push({
19
+ $project: {
20
+ _id: 0,
21
+ ...(projectVerified
22
+ ? createProjects([...project, ...Object.keys(createAndSort)], allowedFieldStrings).$project
23
+ : {}),
24
+ },
25
+ });
26
+ pipeline.push(...createSorts(createAndSort));
27
+ pipeline.push({
28
+ $facet: {
29
+ count: [{ $count: "count" }],
30
+ records: removePagination
31
+ ? []
32
+ : [{ $skip: (pageNumber - 1) * pageSize }, { $limit: pageSize }],
33
+ },
34
+ });
35
+ }
36
+ if (type === "group") {
37
+ verifyGroup(groups, allowedFieldStrings);
38
+ pipeline.push(...createGroups(groups));
39
+ }
40
+ return pipeline;
41
+ };
42
+ //# sourceMappingURL=buildPipeline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildPipeline.js","sourceRoot":"","sources":["../src/buildPipeline.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OA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EAAE,gBAAgB;oBACvB,CAAC,CAAC,EAAE;oBACJ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,UAAU,GAAG,CAAC,CAAC,GAAG,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;aACnE;SACF,CAAC,CAAC;IACL,CAAC;IAED,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;QACrB,WAAW,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;QACzC,QAAQ,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC"}
package/dist/docs.d.ts ADDED
@@ -0,0 +1,126 @@
1
+ export declare const AGGREGATOR_DOCS: {
2
+ readonly "How to get started": "Provide a fieldShapes map (e.g. { 'info.name': 'string', 'games/points': 'number' }) and a request body. fieldShapes describes the shape of every queryable field in your MongoDB documents.";
3
+ readonly "Field Strings": "These are strings representing the fields in your MongoDB record. Some fields contain '/' and others contain '.'. A '.' is used when accessing a field in an object, while a '/' is used when accessing a field in an array. For example, 'info.name' will access the 'name' field in the 'info' object, while 'games/points' will access the 'points' field in the 'games' array, where each item in the array must also have been an object.";
4
+ readonly "Example Body": {
5
+ readonly project: "PROJECT ARRAY";
6
+ readonly filter: "FILTER OBJECT";
7
+ readonly createAndSort: "CREATE AND SORT OBJECT";
8
+ };
9
+ readonly "PROJECT ARRAY": "This is simply an array of fields that you want to see in the response.";
10
+ readonly "Example Project": readonly ["name", "info.city", "games/name", "games/details.points"];
11
+ readonly "FILTER OBJECT": "This will always be an object. It can have three types of keys. The first is '$and', which is an array of filter objects. The second is '$or', which is also an array of filter objects. The third is a field string, which will be the field you want to filter on. The value of this key will be an object with the conditions you want to apply to that field. Possible conditions types are shown in the tag, 'Filter Condition Breakdown'.";
12
+ readonly "Filter Field Key Protocol": "It is possible to use a field key with a suffix of '_any/' or '_all/'. This will change the behavior of the filter. If you use '_any/', it will check if any of the values in the array match the condition. If you use '_all/', it will check if all of the values in the array match the condition. The '_any' or '_all' are used just before the '/' character from the usual field key. You can only use this with 'Filter'.";
13
+ readonly "Example Filter": {
14
+ readonly $or: readonly [{
15
+ readonly "info.city": {
16
+ readonly equals: "New York";
17
+ };
18
+ readonly games: {
19
+ readonly length: {
20
+ readonly greaterThan: 0;
21
+ };
22
+ };
23
+ readonly "games/name": {
24
+ readonly anyOf: readonly ["Chess", "Poker"];
25
+ };
26
+ }, {
27
+ readonly $and: readonly [{
28
+ readonly "info.age": {
29
+ readonly greaterThan: 18;
30
+ };
31
+ readonly "games/details.points": {
32
+ readonly greaterThan: 1000;
33
+ };
34
+ }, {
35
+ readonly "games/name": {
36
+ readonly anyOf: readonly ["Football", "Basketball"];
37
+ };
38
+ }];
39
+ }];
40
+ };
41
+ readonly "Filter Condition Breakdown": {
42
+ readonly "Field Types": {
43
+ readonly date: {
44
+ readonly description: "This is a MongoDB date field. You can use it to filter on dates.";
45
+ readonly conditions: {
46
+ readonly exists: "Boolean";
47
+ readonly equals: "ISO Date String";
48
+ readonly notEquals: "ISO Date String";
49
+ readonly anyOf: "Array of ISO Date Strings: [ ISO Date String ]";
50
+ readonly day: "Mon, Tue, Wed, Thu, Fri, Sat, Sun";
51
+ readonly month: "Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec";
52
+ readonly year: "Number between 1800 and the current year";
53
+ readonly hour: "Number between 0 and 23";
54
+ readonly minute: "Number between 0 and 59";
55
+ readonly second: "Number between 0 and 59";
56
+ readonly isWeekend: "Boolean";
57
+ readonly isWeekday: "Boolean";
58
+ readonly isLeapYear: "Boolean";
59
+ readonly greaterThan: "ISO Date String";
60
+ readonly greaterThanOrEquals: "ISO Date String";
61
+ readonly lessThan: "ISO Date String";
62
+ readonly lessThanOrEquals: "ISO Date String";
63
+ readonly betweenExclusive: "Array of 2 ISO Date Strings: [ ISO Date String, ISO Date String ]";
64
+ readonly betweenInclusive: "Array of 2 ISO Date Strings: [ ISO Date String, ISO Date String ]";
65
+ };
66
+ };
67
+ readonly number: {
68
+ readonly description: "This is a MongoDB number field. You can use it to filter on numbers.";
69
+ readonly conditions: {
70
+ readonly exists: "Boolean";
71
+ readonly equals: "Number";
72
+ readonly notEquals: "Number";
73
+ readonly anyOf: "Array of Numbers: [ Number ]";
74
+ readonly greaterThan: "Number";
75
+ readonly greaterThanOrEquals: "Number";
76
+ readonly lessThan: "Number";
77
+ readonly lessThanOrEquals: "Number";
78
+ readonly betweenExclusive: "Array of 2 Numbers: [ Number, Number ]";
79
+ readonly betweenInclusive: "Array of 2 Numbers: [ Number, Number ]";
80
+ readonly divisibleBy: "Number";
81
+ readonly parity: "'odd' or 'even'";
82
+ };
83
+ };
84
+ readonly string: {
85
+ readonly description: "This is a MongoDB string field. You can use it to filter on strings.";
86
+ readonly conditions: {
87
+ readonly exists: "Boolean";
88
+ readonly equals: "String";
89
+ readonly notEquals: "String";
90
+ readonly anyOf: "Array of Strings: [ String ]";
91
+ readonly contains: "String";
92
+ readonly startsWith: "String";
93
+ readonly endsWith: "String";
94
+ readonly regex: "String";
95
+ readonly length: "This is another conditions object. This will now act as a number field. You must use a number field condition object here.";
96
+ };
97
+ };
98
+ readonly array: {
99
+ readonly description: "This is a MongoDB array field. You can use it to filter on arrays.";
100
+ readonly conditions: {
101
+ readonly exists: "Boolean";
102
+ readonly length: "This is another conditions object. This will now act as a number field. You must use a number field condition object here.";
103
+ };
104
+ };
105
+ readonly boolean: {
106
+ readonly description: "This is a MongoDB boolean field. You can use it to filter on booleans.";
107
+ readonly conditions: {
108
+ readonly exists: "Boolean";
109
+ readonly equals: "Boolean";
110
+ readonly notEquals: "Boolean";
111
+ };
112
+ };
113
+ readonly oid: {
114
+ readonly description: "This is a MongoDB ObjectId field. You can use it to filter on ObjectIds.";
115
+ readonly conditions: {
116
+ readonly exists: "Boolean";
117
+ readonly equals: "String";
118
+ readonly notEquals: "String";
119
+ readonly anyOf: "Array of Strings: [ String ]";
120
+ };
121
+ };
122
+ };
123
+ };
124
+ readonly "CREATE AND SORT OBJECT": "This will always be an object. The keys will always be field strings. Values for each key must be an options object.";
125
+ };
126
+ //# sourceMappingURL=docs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docs.d.ts","sourceRoot":"","sources":["../src/docs.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmIlB,CAAC"}
package/dist/docs.js ADDED
@@ -0,0 +1,123 @@
1
+ export const AGGREGATOR_DOCS = {
2
+ "How to get started": "Provide a fieldShapes map (e.g. { 'info.name': 'string', 'games/points': 'number' }) and a request body. fieldShapes describes the shape of every queryable field in your MongoDB documents.",
3
+ "Field Strings": "These are strings representing the fields in your MongoDB record. Some fields contain '/' and others contain '.'. A '.' is used when accessing a field in an object, while a '/' is used when accessing a field in an array. For example, 'info.name' will access the 'name' field in the 'info' object, while 'games/points' will access the 'points' field in the 'games' array, where each item in the array must also have been an object.",
4
+ "Example Body": {
5
+ project: "PROJECT ARRAY",
6
+ filter: "FILTER OBJECT",
7
+ createAndSort: "CREATE AND SORT OBJECT",
8
+ },
9
+ "PROJECT ARRAY": "This is simply an array of fields that you want to see in the response.",
10
+ "Example Project": [
11
+ "name",
12
+ "info.city",
13
+ "games/name",
14
+ "games/details.points",
15
+ ],
16
+ "FILTER OBJECT": "This will always be an object. It can have three types of keys. The first is '$and', which is an array of filter objects. The second is '$or', which is also an array of filter objects. The third is a field string, which will be the field you want to filter on. The value of this key will be an object with the conditions you want to apply to that field. Possible conditions types are shown in the tag, 'Filter Condition Breakdown'.",
17
+ "Filter Field Key Protocol": "It is possible to use a field key with a suffix of '_any/' or '_all/'. This will change the behavior of the filter. If you use '_any/', it will check if any of the values in the array match the condition. If you use '_all/', it will check if all of the values in the array match the condition. The '_any' or '_all' are used just before the '/' character from the usual field key. You can only use this with 'Filter'.",
18
+ "Example Filter": {
19
+ $or: [
20
+ {
21
+ "info.city": { equals: "New York" },
22
+ games: { length: { greaterThan: 0 } },
23
+ "games/name": { anyOf: ["Chess", "Poker"] },
24
+ },
25
+ {
26
+ $and: [
27
+ {
28
+ "info.age": { greaterThan: 18 },
29
+ "games/details.points": { greaterThan: 1000 },
30
+ },
31
+ {
32
+ "games/name": { anyOf: ["Football", "Basketball"] },
33
+ },
34
+ ],
35
+ },
36
+ ],
37
+ },
38
+ "Filter Condition Breakdown": {
39
+ "Field Types": {
40
+ date: {
41
+ description: "This is a MongoDB date field. You can use it to filter on dates.",
42
+ conditions: {
43
+ exists: "Boolean",
44
+ equals: "ISO Date String",
45
+ notEquals: "ISO Date String",
46
+ anyOf: "Array of ISO Date Strings: [ ISO Date String ]",
47
+ day: "Mon, Tue, Wed, Thu, Fri, Sat, Sun",
48
+ month: "Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec",
49
+ year: "Number between 1800 and the current year",
50
+ hour: "Number between 0 and 23",
51
+ minute: "Number between 0 and 59",
52
+ second: "Number between 0 and 59",
53
+ isWeekend: "Boolean",
54
+ isWeekday: "Boolean",
55
+ isLeapYear: "Boolean",
56
+ greaterThan: "ISO Date String",
57
+ greaterThanOrEquals: "ISO Date String",
58
+ lessThan: "ISO Date String",
59
+ lessThanOrEquals: "ISO Date String",
60
+ betweenExclusive: "Array of 2 ISO Date Strings: [ ISO Date String, ISO Date String ]",
61
+ betweenInclusive: "Array of 2 ISO Date Strings: [ ISO Date String, ISO Date String ]",
62
+ },
63
+ },
64
+ number: {
65
+ description: "This is a MongoDB number field. You can use it to filter on numbers.",
66
+ conditions: {
67
+ exists: "Boolean",
68
+ equals: "Number",
69
+ notEquals: "Number",
70
+ anyOf: "Array of Numbers: [ Number ]",
71
+ greaterThan: "Number",
72
+ greaterThanOrEquals: "Number",
73
+ lessThan: "Number",
74
+ lessThanOrEquals: "Number",
75
+ betweenExclusive: "Array of 2 Numbers: [ Number, Number ]",
76
+ betweenInclusive: "Array of 2 Numbers: [ Number, Number ]",
77
+ divisibleBy: "Number",
78
+ parity: "'odd' or 'even'",
79
+ },
80
+ },
81
+ string: {
82
+ description: "This is a MongoDB string field. You can use it to filter on strings.",
83
+ conditions: {
84
+ exists: "Boolean",
85
+ equals: "String",
86
+ notEquals: "String",
87
+ anyOf: "Array of Strings: [ String ]",
88
+ contains: "String",
89
+ startsWith: "String",
90
+ endsWith: "String",
91
+ regex: "String",
92
+ length: "This is another conditions object. This will now act as a number field. You must use a number field condition object here.",
93
+ },
94
+ },
95
+ array: {
96
+ description: "This is a MongoDB array field. You can use it to filter on arrays.",
97
+ conditions: {
98
+ exists: "Boolean",
99
+ length: "This is another conditions object. This will now act as a number field. You must use a number field condition object here.",
100
+ },
101
+ },
102
+ boolean: {
103
+ description: "This is a MongoDB boolean field. You can use it to filter on booleans.",
104
+ conditions: {
105
+ exists: "Boolean",
106
+ equals: "Boolean",
107
+ notEquals: "Boolean",
108
+ },
109
+ },
110
+ oid: {
111
+ description: "This is a MongoDB ObjectId field. You can use it to filter on ObjectIds.",
112
+ conditions: {
113
+ exists: "Boolean",
114
+ equals: "String",
115
+ notEquals: "String",
116
+ anyOf: "Array of Strings: [ String ]",
117
+ },
118
+ },
119
+ },
120
+ },
121
+ "CREATE AND SORT OBJECT": "This will always be an object. The keys will always be field strings. Values for each key must be an options object.",
122
+ };
123
+ //# sourceMappingURL=docs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docs.js","sourceRoot":"","sources":["../src/docs.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,oBAAoB,EAClB,8LAA8L;IAChM,eAAe,EACb,gbAAgb;IAClb,cAAc,EAAE;QACd,OAAO,EAAE,eAAe;QACxB,MAAM,EAAE,eAAe;QACvB,aAAa,E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E,8BAA8B;iBACtC;aACF;SACF;KACF;IACD,wBAAwB,EACtB,sHAAsH;CAChH,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare class AggregatorError extends Error {
2
+ payload?: unknown;
3
+ constructor(messageOrPayload: string | Record<string, unknown>, payload?: unknown);
4
+ }
5
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,eAAgB,SAAQ,KAAK;IACxC,OAAO,CAAC,EAAE,OAAO,CAAC;gBAEN,gBAAgB,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,OAAO;CAYlF"}
package/dist/errors.js ADDED
@@ -0,0 +1,16 @@
1
+ export class AggregatorError extends Error {
2
+ payload;
3
+ constructor(messageOrPayload, payload) {
4
+ if (typeof messageOrPayload === "string") {
5
+ super(messageOrPayload);
6
+ this.payload = payload;
7
+ }
8
+ else {
9
+ const inner = messageOrPayload.message;
10
+ super(typeof inner === "string" ? inner : "AggregatorError");
11
+ this.payload = messageOrPayload;
12
+ }
13
+ this.name = "AggregatorError";
14
+ }
15
+ }
16
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxC,OAAO,CAAW;IAElB,YAAY,gBAAkD,EAAE,OAAiB;QAC/E,IAAI,OAAO,gBAAgB,KAAK,QAAQ,EAAE,CAAC;YACzC,KAAK,CAAC,gBAAgB,CAAC,CAAC;YACxB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACzB,CAAC;aAAM,CAAC;YACN,MAAM,KAAK,GAAG,gBAAgB,CAAC,OAAO,CAAC;YACvC,KAAK,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC;YAC7D,IAAI,CAAC,OAAO,GAAG,gBAAgB,CAAC;QAClC,CAAC;QAED,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ export { buildPipeline } from "./buildPipeline.js";
2
+ export { aggregate, type AggregateArgs } from "./aggregate.js";
3
+ export { AGGREGATOR_DOCS } from "./docs.js";
4
+ export { AggregatorError } from "./errors.js";
5
+ export type { AggregateResult, AggregatorInput, AggregatorType, CreateAndSort, CreateAndSortCalcType, CreateAndSortField, FieldShape, FieldShapes, FieldFilter, Filter, FilterAnd, FilterOr, GroupAggregateResult, GroupSpec, ListAggregateResult, } from "./types.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,KAAK,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,YAAY,EACV,eAAe,EACf,eAAe,EACf,cAAc,EACd,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,UAAU,EACV,WAAW,EACX,WAAW,EACX,MAAM,EACN,SAAS,EACT,QAAQ,EACR,oBAAoB,EACpB,SAAS,EACT,mBAAmB,GACpB,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { buildPipeline } from "./buildPipeline.js";
2
+ export { aggregate } from "./aggregate.js";
3
+ export { AGGREGATOR_DOCS } from "./docs.js";
4
+ export { AggregatorError } from "./errors.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAsB,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,118 @@
1
+ import { z } from "zod";
2
+ export declare const fieldShapeSchema: z.ZodEnum<["date", "number", "string", "boolean", "array", "oid"]>;
3
+ export declare const fieldShapesSchema: z.ZodRecord<z.ZodString, z.ZodEnum<["date", "number", "string", "boolean", "array", "oid"]>>;
4
+ export declare const createAndSortFieldSchema: z.ZodObject<{
5
+ order: z.ZodDefault<z.ZodEnum<["asc", "desc", "none"]>>;
6
+ type: z.ZodEnum<["sum", "avg", "min", "max", "stdDevPop", "stdDevSamp", "multiply", "concat", "value", "buildArray"]>;
7
+ keepField: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
8
+ value: z.ZodOptional<z.ZodAny>;
9
+ }, "strip", z.ZodTypeAny, {
10
+ type: "sum" | "avg" | "min" | "max" | "stdDevPop" | "stdDevSamp" | "multiply" | "concat" | "value" | "buildArray";
11
+ order: "asc" | "desc" | "none";
12
+ keepField: boolean;
13
+ value?: any;
14
+ }, {
15
+ type: "sum" | "avg" | "min" | "max" | "stdDevPop" | "stdDevSamp" | "multiply" | "concat" | "value" | "buildArray";
16
+ value?: any;
17
+ order?: "asc" | "desc" | "none" | undefined;
18
+ keepField?: boolean | undefined;
19
+ }>;
20
+ export declare const createAndSortSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
21
+ order: z.ZodDefault<z.ZodEnum<["asc", "desc", "none"]>>;
22
+ type: z.ZodEnum<["sum", "avg", "min", "max", "stdDevPop", "stdDevSamp", "multiply", "concat", "value", "buildArray"]>;
23
+ keepField: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
24
+ value: z.ZodOptional<z.ZodAny>;
25
+ }, "strip", z.ZodTypeAny, {
26
+ type: "sum" | "avg" | "min" | "max" | "stdDevPop" | "stdDevSamp" | "multiply" | "concat" | "value" | "buildArray";
27
+ order: "asc" | "desc" | "none";
28
+ keepField: boolean;
29
+ value?: any;
30
+ }, {
31
+ type: "sum" | "avg" | "min" | "max" | "stdDevPop" | "stdDevSamp" | "multiply" | "concat" | "value" | "buildArray";
32
+ value?: any;
33
+ order?: "asc" | "desc" | "none" | undefined;
34
+ keepField?: boolean | undefined;
35
+ }>>;
36
+ export declare const groupSpecSchema: z.ZodObject<{
37
+ key: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
38
+ values: z.ZodDefault<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodString>, "many">>;
39
+ }, "strip", z.ZodTypeAny, {
40
+ values: Record<string, string>[];
41
+ key: string[];
42
+ }, {
43
+ values?: Record<string, string>[] | undefined;
44
+ key?: string[] | undefined;
45
+ }>;
46
+ export declare const aggregatorInputSchema: z.ZodObject<{
47
+ fieldShapes: z.ZodRecord<z.ZodString, z.ZodEnum<["date", "number", "string", "boolean", "array", "oid"]>>;
48
+ type: z.ZodDefault<z.ZodEnum<["list", "group"]>>;
49
+ project: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
50
+ filter: z.ZodDefault<z.ZodAny>;
51
+ createAndSort: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
52
+ order: z.ZodDefault<z.ZodEnum<["asc", "desc", "none"]>>;
53
+ type: z.ZodEnum<["sum", "avg", "min", "max", "stdDevPop", "stdDevSamp", "multiply", "concat", "value", "buildArray"]>;
54
+ keepField: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
55
+ value: z.ZodOptional<z.ZodAny>;
56
+ }, "strip", z.ZodTypeAny, {
57
+ type: "sum" | "avg" | "min" | "max" | "stdDevPop" | "stdDevSamp" | "multiply" | "concat" | "value" | "buildArray";
58
+ order: "asc" | "desc" | "none";
59
+ keepField: boolean;
60
+ value?: any;
61
+ }, {
62
+ type: "sum" | "avg" | "min" | "max" | "stdDevPop" | "stdDevSamp" | "multiply" | "concat" | "value" | "buildArray";
63
+ value?: any;
64
+ order?: "asc" | "desc" | "none" | undefined;
65
+ keepField?: boolean | undefined;
66
+ }>>>;
67
+ pageNumber: z.ZodDefault<z.ZodNumber>;
68
+ pageSize: z.ZodDefault<z.ZodNumber>;
69
+ removePagination: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
70
+ groups: z.ZodDefault<z.ZodOptional<z.ZodObject<{
71
+ key: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
72
+ values: z.ZodDefault<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodString>, "many">>;
73
+ }, "strip", z.ZodTypeAny, {
74
+ values: Record<string, string>[];
75
+ key: string[];
76
+ }, {
77
+ values?: Record<string, string>[] | undefined;
78
+ key?: string[] | undefined;
79
+ }>>>;
80
+ }, "strip", z.ZodTypeAny, {
81
+ type: "list" | "group";
82
+ fieldShapes: Record<string, "string" | "number" | "boolean" | "date" | "array" | "oid">;
83
+ project: string[];
84
+ createAndSort: Record<string, {
85
+ type: "sum" | "avg" | "min" | "max" | "stdDevPop" | "stdDevSamp" | "multiply" | "concat" | "value" | "buildArray";
86
+ order: "asc" | "desc" | "none";
87
+ keepField: boolean;
88
+ value?: any;
89
+ }>;
90
+ pageNumber: number;
91
+ pageSize: number;
92
+ removePagination: boolean;
93
+ groups: {
94
+ values: Record<string, string>[];
95
+ key: string[];
96
+ };
97
+ filter?: any;
98
+ }, {
99
+ fieldShapes: Record<string, "string" | "number" | "boolean" | "date" | "array" | "oid">;
100
+ filter?: any;
101
+ type?: "list" | "group" | undefined;
102
+ project?: string[] | undefined;
103
+ createAndSort?: Record<string, {
104
+ type: "sum" | "avg" | "min" | "max" | "stdDevPop" | "stdDevSamp" | "multiply" | "concat" | "value" | "buildArray";
105
+ value?: any;
106
+ order?: "asc" | "desc" | "none" | undefined;
107
+ keepField?: boolean | undefined;
108
+ }> | undefined;
109
+ pageNumber?: number | undefined;
110
+ pageSize?: number | undefined;
111
+ removePagination?: boolean | undefined;
112
+ groups?: {
113
+ values?: Record<string, string>[] | undefined;
114
+ key?: string[] | undefined;
115
+ } | undefined;
116
+ }>;
117
+ export type ParsedAggregatorInput = z.infer<typeof aggregatorInputSchema>;
118
+ //# sourceMappingURL=inputSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inputSchema.d.ts","sourceRoot":"","sources":["../src/inputSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,gBAAgB,oEAO3B,CAAC;AAEH,eAAO,MAAM,iBAAiB,8FAAyC,CAAC;AAExE,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;EAgBnC,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;GAAiD,CAAC;AAElF,eAAO,MAAM,eAAe;;;;;;;;;EAG1B,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUhC,CAAC;AAEH,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { z } from "zod";
2
+ export const fieldShapeSchema = z.enum([
3
+ "date",
4
+ "number",
5
+ "string",
6
+ "boolean",
7
+ "array",
8
+ "oid",
9
+ ]);
10
+ export const fieldShapesSchema = z.record(z.string(), fieldShapeSchema);
11
+ export const createAndSortFieldSchema = z.object({
12
+ order: z.enum(["asc", "desc", "none"]).default("none"),
13
+ type: z.enum([
14
+ "sum",
15
+ "avg",
16
+ "min",
17
+ "max",
18
+ "stdDevPop",
19
+ "stdDevSamp",
20
+ "multiply",
21
+ "concat",
22
+ "value",
23
+ "buildArray",
24
+ ]),
25
+ keepField: z.boolean().optional().default(false),
26
+ value: z.any().optional(),
27
+ });
28
+ export const createAndSortSchema = z.record(z.string(), createAndSortFieldSchema);
29
+ export const groupSpecSchema = z.object({
30
+ key: z.array(z.string()).default([]),
31
+ values: z.array(z.record(z.string(), z.string())).default([]),
32
+ });
33
+ export const aggregatorInputSchema = z.object({
34
+ fieldShapes: fieldShapesSchema,
35
+ type: z.enum(["list", "group"]).default("list"),
36
+ project: z.array(z.string()).default([]),
37
+ filter: z.any().default({}),
38
+ createAndSort: createAndSortSchema.default({}),
39
+ pageNumber: z.number().int().min(1).default(1),
40
+ pageSize: z.number().int().min(1).max(100000).default(10),
41
+ removePagination: z.boolean().optional().default(false),
42
+ groups: groupSpecSchema.optional().default({ key: [], values: [] }),
43
+ });
44
+ //# sourceMappingURL=inputSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inputSchema.js","sourceRoot":"","sources":["../src/inputSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,IAAI,CAAC;IACrC,MAAM;IACN,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,OAAO;IACP,KAAK;CACN,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,gBAAgB,CAAC,CAAC;AAExE,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/C,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IACtD,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;QACX,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,WAAW;QACX,YAAY;QACZ,UAAU;QACV,QAAQ;QACR,OAAO;QACP,YAA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M,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;IACzD,gBAAgB,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;IACvD,MAAM,EAAE,eAAe,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;CACpE,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { PipelineStage } from "mongoose";
2
+ import type { GroupSpec } from "../types.js";
3
+ export declare const createGroups: (groups: GroupSpec) => PipelineStage[];
4
+ //# sourceMappingURL=createGroups.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createGroups.d.ts","sourceRoot":"","sources":["../../src/pipeline/createGroups.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAI7C,eAAO,MAAM,YAAY,GAAI,QAAQ,SAAS,KAAG,aAAa,EAwE7D,CAAC"}