joye-backend-utility 8.1.0 → 8.1.2

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.
@@ -125,6 +125,7 @@ const UserAnalytic = new mongoose_1.Schema({
125
125
  dailySuggestion: {
126
126
  type: Object,
127
127
  required: false,
128
+ // Never add index: true or compound index on this field — large payload, high write RU.
128
129
  },
129
130
  /** Denormalized from `dailySuggestion != null` for indexed queue-cron filters (avoid `$ne: null`). */
130
131
  hasDailySuggestion: {
@@ -141,7 +142,34 @@ const UserAnalytic = new mongoose_1.Schema({
141
142
  type: Boolean,
142
143
  required: false,
143
144
  },
145
+ /** Claude model used for weekly insights generation (Databricks cron). */
146
+ model: {
147
+ type: String,
148
+ required: false,
149
+ },
150
+ inputToken: {
151
+ type: Number,
152
+ required: false,
153
+ },
154
+ outputToken: {
155
+ type: Number,
156
+ required: false,
157
+ },
158
+ cacheCreationInTokens: {
159
+ type: Number,
160
+ required: false,
161
+ },
162
+ cacheReadInTokens: {
163
+ type: Number,
164
+ required: false,
165
+ },
166
+ serviceTier: {
167
+ type: String,
168
+ required: false,
169
+ },
144
170
  });
171
+ // Allowed compound indexes only — never add `dailySuggestion` (large object → high write RU).
172
+ // `autoIndex` is false in `database.ts`; create indexes manually in Cosmos if needed.
145
173
  UserAnalytic.index({ employeeId: 1, weekNumber: -1, year: -1, date: -1 });
146
174
  UserAnalytic.index({ employeeId: 1, month: -1, year: -1, date: -1 });
147
175
  UserAnalytic.index({ year: 1, weekNumber: 1, bucket: 1, _id: 1 });
@@ -0,0 +1,31 @@
1
+ /**
2
+ * `User_Analytic` Cosmos/Mongo index names.
3
+ *
4
+ * Do NOT index `dailySuggestion` (large object) — it inflates write RU on every upsert.
5
+ * Use `hasDailySuggestion` (boolean) in compound indexes instead.
6
+ */
7
+ /** Manually created in Cosmos for old `$ne: null` cron filter — drop in production. */
8
+ export declare const LEGACY_USER_ANALYTIC_INDEX_NAMES_TO_DROP: readonly ["weekNumber_-1_year_-1_dailySuggestion_1", "weekNumber_1_year_1_dailySuggestion_1"];
9
+ /** Mongoose/Cosmos compound indexes defined in `user_analytic` schema (create if missing). */
10
+ export declare const USER_ANALYTIC_COMPOUND_INDEX_SPECS: readonly [{
11
+ readonly employeeId: 1;
12
+ readonly weekNumber: -1;
13
+ readonly year: -1;
14
+ readonly date: -1;
15
+ }, {
16
+ readonly employeeId: 1;
17
+ readonly month: -1;
18
+ readonly year: -1;
19
+ readonly date: -1;
20
+ }, {
21
+ readonly year: 1;
22
+ readonly weekNumber: 1;
23
+ readonly bucket: 1;
24
+ readonly _id: 1;
25
+ }, {
26
+ readonly year: 1;
27
+ readonly weekNumber: 1;
28
+ readonly hasDailySuggestion: 1;
29
+ readonly bucket: 1;
30
+ readonly _id: 1;
31
+ }];
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ /**
3
+ * `User_Analytic` Cosmos/Mongo index names.
4
+ *
5
+ * Do NOT index `dailySuggestion` (large object) — it inflates write RU on every upsert.
6
+ * Use `hasDailySuggestion` (boolean) in compound indexes instead.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.USER_ANALYTIC_COMPOUND_INDEX_SPECS = exports.LEGACY_USER_ANALYTIC_INDEX_NAMES_TO_DROP = void 0;
10
+ /** Manually created in Cosmos for old `$ne: null` cron filter — drop in production. */
11
+ exports.LEGACY_USER_ANALYTIC_INDEX_NAMES_TO_DROP = [
12
+ 'weekNumber_-1_year_-1_dailySuggestion_1',
13
+ 'weekNumber_1_year_1_dailySuggestion_1',
14
+ ];
15
+ /** Mongoose/Cosmos compound indexes defined in `user_analytic` schema (create if missing). */
16
+ exports.USER_ANALYTIC_COMPOUND_INDEX_SPECS = [
17
+ { employeeId: 1, weekNumber: -1, year: -1, date: -1 },
18
+ { employeeId: 1, month: -1, year: -1, date: -1 },
19
+ { year: 1, weekNumber: 1, bucket: 1, _id: 1 },
20
+ { year: 1, weekNumber: 1, hasDailySuggestion: 1, bucket: 1, _id: 1 },
21
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "joye-backend-utility",
3
- "version": "8.1.0",
3
+ "version": "8.1.2",
4
4
  "description": "Joye backend utility for db functions and common functions",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",