@rpcbase/db 0.74.0 → 0.76.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.
- package/dist/acl/index.js +109 -13
- package/dist/acl/index.js.map +1 -1
- package/dist/index.browser.js +2 -16
- package/dist/index.js +1773 -2069
- package/dist/index.js.map +1 -1
- package/dist/model.js +0 -2
- package/dist/zod-Co_dG17m.js +123 -0
- package/dist/zod-Co_dG17m.js.map +1 -0
- package/package.json +6 -6
- package/dist/can--Y-1LK22.js +0 -132
- package/dist/can--Y-1LK22.js.map +0 -1
- package/dist/index-g1_0RZ-U.js +0 -133
- package/dist/index-g1_0RZ-U.js.map +0 -1
- package/dist/index.browser.js.map +0 -1
- package/dist/model.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,2115 +1,1819 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import { default as default2 } from "mongoose";
|
|
5
|
-
import { z } from "zod";
|
|
6
|
-
import { timingSafeEqual, createHmac } from "node:crypto";
|
|
7
|
-
import { w as withLocalizedStringFallback } from "./index-g1_0RZ-U.js";
|
|
8
|
-
import { a, E, L, c as c2, e as e2, m, r as r2, z as z2, b as b2, f as f2, d as d2 } from "./index-g1_0RZ-U.js";
|
|
9
|
-
import assert from "assert";
|
|
1
|
+
import { buildAbility, buildAbilityFromSession, can, getAccessibleByQuery, getRegisteredPolicies, getTenantRolesFromSessionUser, hasRegisteredPolicy, registerPoliciesFromModules, registerPolicy } from "./acl/index.js";
|
|
2
|
+
import { a as makeZE164Phone, c as buildLocaleFallbackChain, d as zI18nString, f as zLocalizedString, i as E164_PHONE_REGEX, l as resolveLocalizedString, n as extendZod, o as zE164Phone, r as E164_PHONE_OR_EMPTY_REGEX, s as LANGUAGE_CODE_REGEX, t as z, u as withLocalizedStringFallback } from "./zod-Co_dG17m.js";
|
|
3
|
+
import "./model.js";
|
|
10
4
|
import { accessibleBy, accessibleRecordsPlugin } from "@casl/mongoose";
|
|
11
|
-
import "
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
5
|
+
import mongoose, { Schema as Schema$1, Types, default as mongoose$1 } from "mongoose";
|
|
6
|
+
import { z as z$1 } from "zod";
|
|
7
|
+
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
8
|
+
import assert from "assert";
|
|
9
|
+
//#region \0rolldown/runtime.js
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __exportAll = (all, no_symbols) => {
|
|
12
|
+
let target = {};
|
|
13
|
+
for (var name in all) __defProp(target, name, {
|
|
14
|
+
get: all[name],
|
|
15
|
+
enumerable: true
|
|
16
|
+
});
|
|
17
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/models/RBUser.ts
|
|
22
|
+
var ZRBUser = z$1.object({
|
|
23
|
+
email: z$1.string().email().optional(),
|
|
24
|
+
password: z$1.string(),
|
|
25
|
+
name: z$1.string().optional(),
|
|
26
|
+
phone: z$1.string().optional(),
|
|
27
|
+
tenants: z$1.array(z$1.string()),
|
|
28
|
+
tenantRoles: z$1.record(z$1.string(), z$1.array(z$1.string())).optional(),
|
|
29
|
+
oauthProviders: z$1.record(z$1.string(), z$1.object({
|
|
30
|
+
subject: z$1.string(),
|
|
31
|
+
email: z$1.string().email().optional(),
|
|
32
|
+
name: z$1.string().optional(),
|
|
33
|
+
accessToken: z$1.string().optional(),
|
|
34
|
+
refreshToken: z$1.string().optional(),
|
|
35
|
+
idToken: z$1.string().optional(),
|
|
36
|
+
scope: z$1.string().optional(),
|
|
37
|
+
tokenType: z$1.string().optional(),
|
|
38
|
+
expiresAt: z$1.date().optional(),
|
|
39
|
+
rawUserInfo: z$1.unknown().optional(),
|
|
40
|
+
createdAt: z$1.date().optional(),
|
|
41
|
+
updatedAt: z$1.date().optional()
|
|
42
|
+
})).optional(),
|
|
43
|
+
emailVerificationCode: z$1.string().length(6).optional(),
|
|
44
|
+
emailVerificationExpiresAt: z$1.date().optional(),
|
|
45
|
+
passwordResetCode: z$1.string().length(6).optional(),
|
|
46
|
+
passwordResetCodeExpiresAt: z$1.date().optional(),
|
|
47
|
+
passwordResetToken: z$1.string().optional(),
|
|
48
|
+
passwordResetTokenExpiresAt: z$1.date().optional()
|
|
39
49
|
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
required: false
|
|
147
|
-
}
|
|
50
|
+
var RBUserSchema = new Schema$1({
|
|
51
|
+
email: {
|
|
52
|
+
type: String,
|
|
53
|
+
unique: true,
|
|
54
|
+
sparse: true
|
|
55
|
+
},
|
|
56
|
+
phone: {
|
|
57
|
+
type: String,
|
|
58
|
+
unique: true,
|
|
59
|
+
sparse: true
|
|
60
|
+
},
|
|
61
|
+
password: {
|
|
62
|
+
type: String,
|
|
63
|
+
required: true
|
|
64
|
+
},
|
|
65
|
+
name: String,
|
|
66
|
+
tenants: {
|
|
67
|
+
type: [String],
|
|
68
|
+
index: true,
|
|
69
|
+
required: true
|
|
70
|
+
},
|
|
71
|
+
tenantRoles: {
|
|
72
|
+
type: Map,
|
|
73
|
+
of: [String],
|
|
74
|
+
required: false,
|
|
75
|
+
default: {}
|
|
76
|
+
},
|
|
77
|
+
oauthProviders: {
|
|
78
|
+
type: Map,
|
|
79
|
+
of: new Schema$1({
|
|
80
|
+
subject: {
|
|
81
|
+
type: String,
|
|
82
|
+
required: true
|
|
83
|
+
},
|
|
84
|
+
email: {
|
|
85
|
+
type: String,
|
|
86
|
+
required: false
|
|
87
|
+
},
|
|
88
|
+
name: {
|
|
89
|
+
type: String,
|
|
90
|
+
required: false
|
|
91
|
+
},
|
|
92
|
+
accessToken: {
|
|
93
|
+
type: String,
|
|
94
|
+
required: false
|
|
95
|
+
},
|
|
96
|
+
refreshToken: {
|
|
97
|
+
type: String,
|
|
98
|
+
required: false
|
|
99
|
+
},
|
|
100
|
+
idToken: {
|
|
101
|
+
type: String,
|
|
102
|
+
required: false
|
|
103
|
+
},
|
|
104
|
+
scope: {
|
|
105
|
+
type: String,
|
|
106
|
+
required: false
|
|
107
|
+
},
|
|
108
|
+
tokenType: {
|
|
109
|
+
type: String,
|
|
110
|
+
required: false
|
|
111
|
+
},
|
|
112
|
+
expiresAt: {
|
|
113
|
+
type: Date,
|
|
114
|
+
required: false
|
|
115
|
+
},
|
|
116
|
+
rawUserInfo: {
|
|
117
|
+
type: Schema$1.Types.Mixed,
|
|
118
|
+
required: false
|
|
119
|
+
},
|
|
120
|
+
createdAt: {
|
|
121
|
+
type: Date,
|
|
122
|
+
required: false
|
|
123
|
+
},
|
|
124
|
+
updatedAt: {
|
|
125
|
+
type: Date,
|
|
126
|
+
required: false
|
|
127
|
+
}
|
|
128
|
+
}, { _id: false }),
|
|
129
|
+
default: {},
|
|
130
|
+
required: false
|
|
131
|
+
},
|
|
132
|
+
emailVerificationCode: {
|
|
133
|
+
type: String,
|
|
134
|
+
required: false
|
|
135
|
+
},
|
|
136
|
+
emailVerificationExpiresAt: {
|
|
137
|
+
type: Date,
|
|
138
|
+
required: false
|
|
139
|
+
},
|
|
140
|
+
passwordResetCode: {
|
|
141
|
+
type: String,
|
|
142
|
+
required: false
|
|
143
|
+
},
|
|
144
|
+
passwordResetCodeExpiresAt: {
|
|
145
|
+
type: Date,
|
|
146
|
+
required: false
|
|
147
|
+
},
|
|
148
|
+
passwordResetToken: {
|
|
149
|
+
type: String,
|
|
150
|
+
required: false
|
|
151
|
+
},
|
|
152
|
+
passwordResetTokenExpiresAt: {
|
|
153
|
+
type: Date,
|
|
154
|
+
required: false
|
|
155
|
+
}
|
|
148
156
|
});
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
157
|
+
//#endregion
|
|
158
|
+
//#region src/models/RBTenant.ts
|
|
159
|
+
var ZRBTenant = z$1.object({
|
|
160
|
+
tenantId: z$1.string(),
|
|
161
|
+
parentTenantId: z$1.string().optional(),
|
|
162
|
+
name: z$1.string().optional()
|
|
153
163
|
});
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
},
|
|
164
|
-
name: {
|
|
165
|
-
type: String
|
|
166
|
-
}
|
|
164
|
+
var RBTenantSchema = new Schema$1({
|
|
165
|
+
tenantId: {
|
|
166
|
+
type: String,
|
|
167
|
+
required: true,
|
|
168
|
+
unique: true,
|
|
169
|
+
index: true
|
|
170
|
+
},
|
|
171
|
+
parentTenantId: { type: String },
|
|
172
|
+
name: { type: String }
|
|
167
173
|
});
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region src/models/RBTenantSubscription.ts
|
|
176
|
+
var ZRBTenantSubscriptionStatus = z$1.enum([
|
|
177
|
+
"trialing",
|
|
178
|
+
"active",
|
|
179
|
+
"past_due",
|
|
180
|
+
"paused",
|
|
181
|
+
"canceled",
|
|
182
|
+
"expired"
|
|
183
|
+
]);
|
|
184
|
+
var ZRBTenantSubscriptionIntervalUnit = z$1.enum(["month", "year"]);
|
|
185
|
+
var ZRBTenantSubscriptionType = z$1.enum(["primary", "addon"]);
|
|
186
|
+
var ZRBTenantSubscriptionScope = z$1.enum([
|
|
187
|
+
"tenant",
|
|
188
|
+
"shop",
|
|
189
|
+
"custom"
|
|
190
|
+
]);
|
|
191
|
+
var ZRBTenantSubscription = z$1.object({
|
|
192
|
+
tenantId: z$1.string(),
|
|
193
|
+
subscriptionId: z$1.string(),
|
|
194
|
+
type: ZRBTenantSubscriptionType.optional(),
|
|
195
|
+
parentSubscriptionId: z$1.string().optional(),
|
|
196
|
+
scope: ZRBTenantSubscriptionScope.optional(),
|
|
197
|
+
scopeId: z$1.string().optional(),
|
|
198
|
+
planKey: z$1.string(),
|
|
199
|
+
status: ZRBTenantSubscriptionStatus,
|
|
200
|
+
intervalUnit: ZRBTenantSubscriptionIntervalUnit,
|
|
201
|
+
intervalCount: z$1.number().int().min(1).optional(),
|
|
202
|
+
modules: z$1.array(z$1.string()).optional(),
|
|
203
|
+
currentPeriodStart: z$1.date().optional(),
|
|
204
|
+
currentPeriodEnd: z$1.date().optional(),
|
|
205
|
+
trialEndsAt: z$1.date().optional(),
|
|
206
|
+
cancelAt: z$1.date().optional(),
|
|
207
|
+
cancelAtPeriodEnd: z$1.boolean().optional(),
|
|
208
|
+
canceledAt: z$1.date().optional(),
|
|
209
|
+
provider: z$1.string().optional(),
|
|
210
|
+
providerCustomerId: z$1.string().optional(),
|
|
211
|
+
providerSubscriptionId: z$1.string().optional(),
|
|
212
|
+
latestEventId: z$1.string().optional(),
|
|
213
|
+
latestEventAt: z$1.date().optional(),
|
|
214
|
+
metadata: z$1.record(z$1.string(), z$1.unknown()).optional()
|
|
196
215
|
});
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
},
|
|
259
|
-
cancelAtPeriodEnd: {
|
|
260
|
-
type: Boolean,
|
|
261
|
-
default: false
|
|
262
|
-
},
|
|
263
|
-
canceledAt: {
|
|
264
|
-
type: Date
|
|
265
|
-
},
|
|
266
|
-
provider: {
|
|
267
|
-
type: String
|
|
268
|
-
},
|
|
269
|
-
providerCustomerId: {
|
|
270
|
-
type: String
|
|
271
|
-
},
|
|
272
|
-
providerSubscriptionId: {
|
|
273
|
-
type: String
|
|
274
|
-
},
|
|
275
|
-
latestEventId: {
|
|
276
|
-
type: String
|
|
277
|
-
},
|
|
278
|
-
latestEventAt: {
|
|
279
|
-
type: Date
|
|
280
|
-
},
|
|
281
|
-
metadata: {
|
|
282
|
-
type: Schema$1.Types.Mixed
|
|
283
|
-
}
|
|
216
|
+
var RBTenantSubscriptionSchema = new Schema$1({
|
|
217
|
+
tenantId: {
|
|
218
|
+
type: String,
|
|
219
|
+
required: true,
|
|
220
|
+
index: true
|
|
221
|
+
},
|
|
222
|
+
subscriptionId: {
|
|
223
|
+
type: String,
|
|
224
|
+
required: true
|
|
225
|
+
},
|
|
226
|
+
type: {
|
|
227
|
+
type: String,
|
|
228
|
+
required: true,
|
|
229
|
+
enum: ZRBTenantSubscriptionType.options,
|
|
230
|
+
default: "primary"
|
|
231
|
+
},
|
|
232
|
+
parentSubscriptionId: { type: String },
|
|
233
|
+
scope: {
|
|
234
|
+
type: String,
|
|
235
|
+
enum: ZRBTenantSubscriptionScope.options,
|
|
236
|
+
default: "tenant"
|
|
237
|
+
},
|
|
238
|
+
scopeId: { type: String },
|
|
239
|
+
planKey: {
|
|
240
|
+
type: String,
|
|
241
|
+
required: true
|
|
242
|
+
},
|
|
243
|
+
status: {
|
|
244
|
+
type: String,
|
|
245
|
+
required: true,
|
|
246
|
+
enum: ZRBTenantSubscriptionStatus.options
|
|
247
|
+
},
|
|
248
|
+
intervalUnit: {
|
|
249
|
+
type: String,
|
|
250
|
+
required: true,
|
|
251
|
+
enum: ZRBTenantSubscriptionIntervalUnit.options
|
|
252
|
+
},
|
|
253
|
+
intervalCount: {
|
|
254
|
+
type: Number,
|
|
255
|
+
min: 1,
|
|
256
|
+
default: 1
|
|
257
|
+
},
|
|
258
|
+
modules: {
|
|
259
|
+
type: [String],
|
|
260
|
+
default: []
|
|
261
|
+
},
|
|
262
|
+
currentPeriodStart: { type: Date },
|
|
263
|
+
currentPeriodEnd: { type: Date },
|
|
264
|
+
trialEndsAt: { type: Date },
|
|
265
|
+
cancelAt: { type: Date },
|
|
266
|
+
cancelAtPeriodEnd: {
|
|
267
|
+
type: Boolean,
|
|
268
|
+
default: false
|
|
269
|
+
},
|
|
270
|
+
canceledAt: { type: Date },
|
|
271
|
+
provider: { type: String },
|
|
272
|
+
providerCustomerId: { type: String },
|
|
273
|
+
providerSubscriptionId: { type: String },
|
|
274
|
+
latestEventId: { type: String },
|
|
275
|
+
latestEventAt: { type: Date },
|
|
276
|
+
metadata: { type: Schema$1.Types.Mixed }
|
|
284
277
|
});
|
|
285
278
|
RBTenantSubscriptionSchema.index({
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}, {
|
|
289
|
-
unique: true
|
|
290
|
-
});
|
|
279
|
+
tenantId: 1,
|
|
280
|
+
subscriptionId: 1
|
|
281
|
+
}, { unique: true });
|
|
291
282
|
RBTenantSubscriptionSchema.index({
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
283
|
+
tenantId: 1,
|
|
284
|
+
scope: 1,
|
|
285
|
+
scopeId: 1
|
|
295
286
|
});
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
287
|
+
//#endregion
|
|
288
|
+
//#region src/models/RBTenantSubscriptionEvent.ts
|
|
289
|
+
var ZRBTenantSubscriptionEventSource = z$1.enum([
|
|
290
|
+
"admin",
|
|
291
|
+
"system",
|
|
292
|
+
"webhook",
|
|
293
|
+
"user"
|
|
294
|
+
]);
|
|
295
|
+
var ZRBTenantSubscriptionChangeDirection = z$1.enum([
|
|
296
|
+
"upgrade",
|
|
297
|
+
"downgrade",
|
|
298
|
+
"lateral"
|
|
299
|
+
]);
|
|
300
|
+
var ZRBTenantSubscriptionEvent = z$1.object({
|
|
301
|
+
tenantId: z$1.string(),
|
|
302
|
+
subscriptionId: z$1.string(),
|
|
303
|
+
type: z$1.string(),
|
|
304
|
+
occurredAt: z$1.date(),
|
|
305
|
+
effectiveAt: z$1.date().optional(),
|
|
306
|
+
fromPlanKey: z$1.string().optional(),
|
|
307
|
+
toPlanKey: z$1.string().optional(),
|
|
308
|
+
fromStatus: ZRBTenantSubscriptionStatus.optional(),
|
|
309
|
+
toStatus: ZRBTenantSubscriptionStatus.optional(),
|
|
310
|
+
fromModules: z$1.array(z$1.string()).optional(),
|
|
311
|
+
toModules: z$1.array(z$1.string()).optional(),
|
|
312
|
+
fromIntervalUnit: ZRBTenantSubscriptionIntervalUnit.optional(),
|
|
313
|
+
toIntervalUnit: ZRBTenantSubscriptionIntervalUnit.optional(),
|
|
314
|
+
fromIntervalCount: z$1.number().int().min(1).optional(),
|
|
315
|
+
toIntervalCount: z$1.number().int().min(1).optional(),
|
|
316
|
+
direction: ZRBTenantSubscriptionChangeDirection.optional(),
|
|
317
|
+
actorUserId: z$1.string().optional(),
|
|
318
|
+
source: ZRBTenantSubscriptionEventSource.optional(),
|
|
319
|
+
reason: z$1.string().optional(),
|
|
320
|
+
provider: z$1.string().optional(),
|
|
321
|
+
providerEventId: z$1.string().optional(),
|
|
322
|
+
providerPayload: z$1.unknown().optional(),
|
|
323
|
+
metadata: z$1.record(z$1.string(), z$1.unknown()).optional()
|
|
322
324
|
});
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
type: String,
|
|
393
|
-
enum: ZRBTenantSubscriptionEventSource.options
|
|
394
|
-
},
|
|
395
|
-
reason: {
|
|
396
|
-
type: String
|
|
397
|
-
},
|
|
398
|
-
provider: {
|
|
399
|
-
type: String
|
|
400
|
-
},
|
|
401
|
-
providerEventId: {
|
|
402
|
-
type: String
|
|
403
|
-
},
|
|
404
|
-
providerPayload: {
|
|
405
|
-
type: Schema$1.Types.Mixed
|
|
406
|
-
},
|
|
407
|
-
metadata: {
|
|
408
|
-
type: Schema$1.Types.Mixed
|
|
409
|
-
}
|
|
325
|
+
var RBTenantSubscriptionEventSchema = new Schema$1({
|
|
326
|
+
tenantId: {
|
|
327
|
+
type: String,
|
|
328
|
+
required: true,
|
|
329
|
+
index: true
|
|
330
|
+
},
|
|
331
|
+
subscriptionId: {
|
|
332
|
+
type: String,
|
|
333
|
+
required: true,
|
|
334
|
+
index: true
|
|
335
|
+
},
|
|
336
|
+
type: {
|
|
337
|
+
type: String,
|
|
338
|
+
required: true
|
|
339
|
+
},
|
|
340
|
+
occurredAt: {
|
|
341
|
+
type: Date,
|
|
342
|
+
required: true,
|
|
343
|
+
default: Date.now
|
|
344
|
+
},
|
|
345
|
+
effectiveAt: { type: Date },
|
|
346
|
+
fromPlanKey: { type: String },
|
|
347
|
+
toPlanKey: { type: String },
|
|
348
|
+
fromStatus: {
|
|
349
|
+
type: String,
|
|
350
|
+
enum: ZRBTenantSubscriptionStatus.options
|
|
351
|
+
},
|
|
352
|
+
toStatus: {
|
|
353
|
+
type: String,
|
|
354
|
+
enum: ZRBTenantSubscriptionStatus.options
|
|
355
|
+
},
|
|
356
|
+
fromModules: {
|
|
357
|
+
type: [String],
|
|
358
|
+
default: void 0
|
|
359
|
+
},
|
|
360
|
+
toModules: {
|
|
361
|
+
type: [String],
|
|
362
|
+
default: void 0
|
|
363
|
+
},
|
|
364
|
+
fromIntervalUnit: {
|
|
365
|
+
type: String,
|
|
366
|
+
enum: ZRBTenantSubscriptionIntervalUnit.options
|
|
367
|
+
},
|
|
368
|
+
toIntervalUnit: {
|
|
369
|
+
type: String,
|
|
370
|
+
enum: ZRBTenantSubscriptionIntervalUnit.options
|
|
371
|
+
},
|
|
372
|
+
fromIntervalCount: {
|
|
373
|
+
type: Number,
|
|
374
|
+
min: 1
|
|
375
|
+
},
|
|
376
|
+
toIntervalCount: {
|
|
377
|
+
type: Number,
|
|
378
|
+
min: 1
|
|
379
|
+
},
|
|
380
|
+
direction: {
|
|
381
|
+
type: String,
|
|
382
|
+
enum: ZRBTenantSubscriptionChangeDirection.options
|
|
383
|
+
},
|
|
384
|
+
actorUserId: { type: String },
|
|
385
|
+
source: {
|
|
386
|
+
type: String,
|
|
387
|
+
enum: ZRBTenantSubscriptionEventSource.options
|
|
388
|
+
},
|
|
389
|
+
reason: { type: String },
|
|
390
|
+
provider: { type: String },
|
|
391
|
+
providerEventId: { type: String },
|
|
392
|
+
providerPayload: { type: Schema$1.Types.Mixed },
|
|
393
|
+
metadata: { type: Schema$1.Types.Mixed }
|
|
410
394
|
});
|
|
411
395
|
RBTenantSubscriptionEventSchema.index({
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
396
|
+
tenantId: 1,
|
|
397
|
+
subscriptionId: 1,
|
|
398
|
+
occurredAt: 1
|
|
415
399
|
});
|
|
416
400
|
RBTenantSubscriptionEventSchema.index({
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
}, {
|
|
420
|
-
unique: true,
|
|
421
|
-
sparse: true
|
|
422
|
-
});
|
|
423
|
-
const ZRBRtsCounter = z.object({
|
|
424
|
-
_id: z.string(),
|
|
425
|
-
seq: z.number().int().min(0)
|
|
426
|
-
});
|
|
427
|
-
const RBRtsCounterSchema = new Schema$1({
|
|
428
|
-
_id: {
|
|
429
|
-
type: String,
|
|
430
|
-
required: true
|
|
431
|
-
},
|
|
432
|
-
seq: {
|
|
433
|
-
type: Number,
|
|
434
|
-
required: true,
|
|
435
|
-
default: 0
|
|
436
|
-
}
|
|
401
|
+
provider: 1,
|
|
402
|
+
providerEventId: 1
|
|
437
403
|
}, {
|
|
438
|
-
|
|
404
|
+
unique: true,
|
|
405
|
+
sparse: true
|
|
439
406
|
});
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
modelName: z.string(),
|
|
446
|
-
op: ZRBRtsChangeOp,
|
|
447
|
-
docId: z.string().optional(),
|
|
448
|
-
ts: z.date()
|
|
407
|
+
//#endregion
|
|
408
|
+
//#region src/models/RBRtsCounter.ts
|
|
409
|
+
var ZRBRtsCounter = z$1.object({
|
|
410
|
+
_id: z$1.string(),
|
|
411
|
+
seq: z$1.number().int().min(0)
|
|
449
412
|
});
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
default: Date.now
|
|
473
|
-
}
|
|
474
|
-
}, {
|
|
475
|
-
versionKey: false
|
|
476
|
-
});
|
|
477
|
-
RBRtsChangeSchema.index({
|
|
478
|
-
seq: 1
|
|
479
|
-
}, {
|
|
480
|
-
unique: true
|
|
413
|
+
var RBRtsCounterSchema = new Schema$1({
|
|
414
|
+
_id: {
|
|
415
|
+
type: String,
|
|
416
|
+
required: true
|
|
417
|
+
},
|
|
418
|
+
seq: {
|
|
419
|
+
type: Number,
|
|
420
|
+
required: true,
|
|
421
|
+
default: 0
|
|
422
|
+
}
|
|
423
|
+
}, { versionKey: false });
|
|
424
|
+
//#endregion
|
|
425
|
+
//#region src/models/RBRtsChange.ts
|
|
426
|
+
var ttlSecondsRaw = process.env.RB_RTS_CHANGES_TTL_S ?? "";
|
|
427
|
+
var ttlSeconds = Number.isFinite(Number(ttlSecondsRaw)) ? Math.max(60, Math.floor(Number(ttlSecondsRaw))) : 3600 * 24 * 30;
|
|
428
|
+
var ZRBRtsChangeOp = z$1.enum(["delete", "reset_model"]);
|
|
429
|
+
var ZRBRtsChange = z$1.object({
|
|
430
|
+
seq: z$1.number().int().min(0),
|
|
431
|
+
modelName: z$1.string(),
|
|
432
|
+
op: ZRBRtsChangeOp,
|
|
433
|
+
docId: z$1.string().optional(),
|
|
434
|
+
ts: z$1.date()
|
|
481
435
|
});
|
|
482
|
-
RBRtsChangeSchema
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
required: true
|
|
533
|
-
},
|
|
534
|
-
chunksTotal: {
|
|
535
|
-
type: Number,
|
|
536
|
-
required: true
|
|
537
|
-
},
|
|
538
|
-
status: {
|
|
539
|
-
type: String,
|
|
540
|
-
required: true,
|
|
541
|
-
enum: ZRBUploadSessionStatus.options
|
|
542
|
-
},
|
|
543
|
-
createdAt: {
|
|
544
|
-
type: Date,
|
|
545
|
-
required: true,
|
|
546
|
-
default: Date.now
|
|
547
|
-
},
|
|
548
|
-
expiresAt: {
|
|
549
|
-
type: Date,
|
|
550
|
-
required: true
|
|
551
|
-
},
|
|
552
|
-
fileId: {
|
|
553
|
-
type: String,
|
|
554
|
-
required: false
|
|
555
|
-
},
|
|
556
|
-
isPublic: {
|
|
557
|
-
type: Boolean,
|
|
558
|
-
required: false
|
|
559
|
-
},
|
|
560
|
-
error: {
|
|
561
|
-
type: String,
|
|
562
|
-
required: false
|
|
563
|
-
}
|
|
564
|
-
}, {
|
|
565
|
-
versionKey: false
|
|
566
|
-
});
|
|
567
|
-
RBUploadSessionSchema.index({
|
|
568
|
-
expiresAt: 1
|
|
569
|
-
}, {
|
|
570
|
-
expireAfterSeconds: 0
|
|
571
|
-
});
|
|
572
|
-
const RBUploadSessionPolicy = {
|
|
573
|
-
subject: "RBUploadSession",
|
|
574
|
-
define: (builder, ctx) => {
|
|
575
|
-
builder.can("create", "RBUploadSession");
|
|
576
|
-
if (ctx.userId) {
|
|
577
|
-
builder.can("read", "RBUploadSession", {
|
|
578
|
-
userId: ctx.userId
|
|
579
|
-
});
|
|
580
|
-
builder.can("update", "RBUploadSession", {
|
|
581
|
-
userId: ctx.userId
|
|
582
|
-
});
|
|
583
|
-
builder.can("delete", "RBUploadSession", {
|
|
584
|
-
userId: ctx.userId
|
|
585
|
-
});
|
|
586
|
-
}
|
|
587
|
-
const uploadKeyHash = typeof ctx.claims?.uploadKeyHash === "string" ? ctx.claims.uploadKeyHash.trim() : "";
|
|
588
|
-
if (uploadKeyHash) {
|
|
589
|
-
builder.can("read", "RBUploadSession", {
|
|
590
|
-
ownerKeyHash: uploadKeyHash
|
|
591
|
-
});
|
|
592
|
-
builder.can("update", "RBUploadSession", {
|
|
593
|
-
ownerKeyHash: uploadKeyHash
|
|
594
|
-
});
|
|
595
|
-
builder.can("delete", "RBUploadSession", {
|
|
596
|
-
ownerKeyHash: uploadKeyHash
|
|
597
|
-
});
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
};
|
|
601
|
-
const ZRBUploadChunk = z.object({
|
|
602
|
-
uploadId: z.string(),
|
|
603
|
-
index: z.number().int().min(0),
|
|
604
|
-
data: z.unknown(),
|
|
605
|
-
size: z.number().int().min(0),
|
|
606
|
-
sha256: z.string().optional(),
|
|
607
|
-
createdAt: z.date(),
|
|
608
|
-
expiresAt: z.date()
|
|
609
|
-
});
|
|
610
|
-
const RBUploadChunkSchema = new Schema$1({
|
|
611
|
-
uploadId: {
|
|
612
|
-
type: String,
|
|
613
|
-
required: true,
|
|
614
|
-
index: true
|
|
615
|
-
},
|
|
616
|
-
index: {
|
|
617
|
-
type: Number,
|
|
618
|
-
required: true
|
|
619
|
-
},
|
|
620
|
-
data: {
|
|
621
|
-
type: Buffer,
|
|
622
|
-
required: true
|
|
623
|
-
},
|
|
624
|
-
size: {
|
|
625
|
-
type: Number,
|
|
626
|
-
required: true
|
|
627
|
-
},
|
|
628
|
-
sha256: {
|
|
629
|
-
type: String,
|
|
630
|
-
required: false
|
|
631
|
-
},
|
|
632
|
-
createdAt: {
|
|
633
|
-
type: Date,
|
|
634
|
-
required: true,
|
|
635
|
-
default: Date.now
|
|
636
|
-
},
|
|
637
|
-
expiresAt: {
|
|
638
|
-
type: Date,
|
|
639
|
-
required: true
|
|
640
|
-
}
|
|
641
|
-
}, {
|
|
642
|
-
versionKey: false
|
|
436
|
+
var RBRtsChangeSchema = new Schema$1({
|
|
437
|
+
seq: {
|
|
438
|
+
type: Number,
|
|
439
|
+
required: true
|
|
440
|
+
},
|
|
441
|
+
modelName: {
|
|
442
|
+
type: String,
|
|
443
|
+
required: true,
|
|
444
|
+
index: true
|
|
445
|
+
},
|
|
446
|
+
op: {
|
|
447
|
+
type: String,
|
|
448
|
+
required: true,
|
|
449
|
+
enum: ZRBRtsChangeOp.options
|
|
450
|
+
},
|
|
451
|
+
docId: {
|
|
452
|
+
type: String,
|
|
453
|
+
required: false
|
|
454
|
+
},
|
|
455
|
+
ts: {
|
|
456
|
+
type: Date,
|
|
457
|
+
required: true,
|
|
458
|
+
default: Date.now
|
|
459
|
+
}
|
|
460
|
+
}, { versionKey: false });
|
|
461
|
+
RBRtsChangeSchema.index({ seq: 1 }, { unique: true });
|
|
462
|
+
RBRtsChangeSchema.index({ ts: 1 }, { expireAfterSeconds: ttlSeconds });
|
|
463
|
+
//#endregion
|
|
464
|
+
//#region src/models/RBUploadSession.ts
|
|
465
|
+
var ZRBUploadSessionStatus = z$1.enum([
|
|
466
|
+
"uploading",
|
|
467
|
+
"assembling",
|
|
468
|
+
"done",
|
|
469
|
+
"error"
|
|
470
|
+
]);
|
|
471
|
+
var ZRBUploadSession = z$1.object({
|
|
472
|
+
_id: z$1.string(),
|
|
473
|
+
userId: z$1.string().optional(),
|
|
474
|
+
ownerKeyHash: z$1.string().optional(),
|
|
475
|
+
filename: z$1.string(),
|
|
476
|
+
mimeType: z$1.string(),
|
|
477
|
+
totalSize: z$1.number().int().min(0),
|
|
478
|
+
chunkSize: z$1.number().int().min(1),
|
|
479
|
+
chunksTotal: z$1.number().int().min(1),
|
|
480
|
+
status: ZRBUploadSessionStatus,
|
|
481
|
+
createdAt: z$1.date(),
|
|
482
|
+
expiresAt: z$1.date(),
|
|
483
|
+
fileId: z$1.string().optional(),
|
|
484
|
+
isPublic: z$1.boolean().optional(),
|
|
485
|
+
error: z$1.string().optional()
|
|
643
486
|
});
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
487
|
+
var RBUploadSessionSchema = new Schema$1({
|
|
488
|
+
_id: {
|
|
489
|
+
type: String,
|
|
490
|
+
required: true
|
|
491
|
+
},
|
|
492
|
+
userId: {
|
|
493
|
+
type: String,
|
|
494
|
+
required: false,
|
|
495
|
+
index: true
|
|
496
|
+
},
|
|
497
|
+
ownerKeyHash: {
|
|
498
|
+
type: String,
|
|
499
|
+
required: false
|
|
500
|
+
},
|
|
501
|
+
filename: {
|
|
502
|
+
type: String,
|
|
503
|
+
required: true
|
|
504
|
+
},
|
|
505
|
+
mimeType: {
|
|
506
|
+
type: String,
|
|
507
|
+
required: true
|
|
508
|
+
},
|
|
509
|
+
totalSize: {
|
|
510
|
+
type: Number,
|
|
511
|
+
required: true
|
|
512
|
+
},
|
|
513
|
+
chunkSize: {
|
|
514
|
+
type: Number,
|
|
515
|
+
required: true
|
|
516
|
+
},
|
|
517
|
+
chunksTotal: {
|
|
518
|
+
type: Number,
|
|
519
|
+
required: true
|
|
520
|
+
},
|
|
521
|
+
status: {
|
|
522
|
+
type: String,
|
|
523
|
+
required: true,
|
|
524
|
+
enum: ZRBUploadSessionStatus.options
|
|
525
|
+
},
|
|
526
|
+
createdAt: {
|
|
527
|
+
type: Date,
|
|
528
|
+
required: true,
|
|
529
|
+
default: Date.now
|
|
530
|
+
},
|
|
531
|
+
expiresAt: {
|
|
532
|
+
type: Date,
|
|
533
|
+
required: true
|
|
534
|
+
},
|
|
535
|
+
fileId: {
|
|
536
|
+
type: String,
|
|
537
|
+
required: false
|
|
538
|
+
},
|
|
539
|
+
isPublic: {
|
|
540
|
+
type: Boolean,
|
|
541
|
+
required: false
|
|
542
|
+
},
|
|
543
|
+
error: {
|
|
544
|
+
type: String,
|
|
545
|
+
required: false
|
|
546
|
+
}
|
|
547
|
+
}, { versionKey: false });
|
|
548
|
+
RBUploadSessionSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
|
|
549
|
+
var RBUploadSessionPolicy = {
|
|
550
|
+
subject: "RBUploadSession",
|
|
551
|
+
define: (builder, ctx) => {
|
|
552
|
+
builder.can("create", "RBUploadSession");
|
|
553
|
+
if (ctx.userId) {
|
|
554
|
+
builder.can("read", "RBUploadSession", { userId: ctx.userId });
|
|
555
|
+
builder.can("update", "RBUploadSession", { userId: ctx.userId });
|
|
556
|
+
builder.can("delete", "RBUploadSession", { userId: ctx.userId });
|
|
557
|
+
}
|
|
558
|
+
const uploadKeyHash = typeof ctx.claims?.uploadKeyHash === "string" ? ctx.claims.uploadKeyHash.trim() : "";
|
|
559
|
+
if (uploadKeyHash) {
|
|
560
|
+
builder.can("read", "RBUploadSession", { ownerKeyHash: uploadKeyHash });
|
|
561
|
+
builder.can("update", "RBUploadSession", { ownerKeyHash: uploadKeyHash });
|
|
562
|
+
builder.can("delete", "RBUploadSession", { ownerKeyHash: uploadKeyHash });
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
};
|
|
566
|
+
//#endregion
|
|
567
|
+
//#region src/models/RBUploadChunk.ts
|
|
568
|
+
var ZRBUploadChunk = z$1.object({
|
|
569
|
+
uploadId: z$1.string(),
|
|
570
|
+
index: z$1.number().int().min(0),
|
|
571
|
+
data: z$1.unknown(),
|
|
572
|
+
size: z$1.number().int().min(0),
|
|
573
|
+
sha256: z$1.string().optional(),
|
|
574
|
+
createdAt: z$1.date(),
|
|
575
|
+
expiresAt: z$1.date()
|
|
649
576
|
});
|
|
577
|
+
var RBUploadChunkSchema = new Schema$1({
|
|
578
|
+
uploadId: {
|
|
579
|
+
type: String,
|
|
580
|
+
required: true,
|
|
581
|
+
index: true
|
|
582
|
+
},
|
|
583
|
+
index: {
|
|
584
|
+
type: Number,
|
|
585
|
+
required: true
|
|
586
|
+
},
|
|
587
|
+
data: {
|
|
588
|
+
type: Buffer,
|
|
589
|
+
required: true
|
|
590
|
+
},
|
|
591
|
+
size: {
|
|
592
|
+
type: Number,
|
|
593
|
+
required: true
|
|
594
|
+
},
|
|
595
|
+
sha256: {
|
|
596
|
+
type: String,
|
|
597
|
+
required: false
|
|
598
|
+
},
|
|
599
|
+
createdAt: {
|
|
600
|
+
type: Date,
|
|
601
|
+
required: true,
|
|
602
|
+
default: Date.now
|
|
603
|
+
},
|
|
604
|
+
expiresAt: {
|
|
605
|
+
type: Date,
|
|
606
|
+
required: true
|
|
607
|
+
}
|
|
608
|
+
}, { versionKey: false });
|
|
650
609
|
RBUploadChunkSchema.index({
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
});
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
const RBNotificationSchema = new Schema$1({
|
|
669
|
-
userId: {
|
|
670
|
-
type: String,
|
|
671
|
-
required: true,
|
|
672
|
-
index: true
|
|
673
|
-
},
|
|
674
|
-
topic: {
|
|
675
|
-
type: String,
|
|
676
|
-
required: false,
|
|
677
|
-
index: true
|
|
678
|
-
},
|
|
679
|
-
title: {
|
|
680
|
-
type: String,
|
|
681
|
-
required: true
|
|
682
|
-
},
|
|
683
|
-
body: {
|
|
684
|
-
type: String,
|
|
685
|
-
required: false
|
|
686
|
-
},
|
|
687
|
-
url: {
|
|
688
|
-
type: String,
|
|
689
|
-
required: false
|
|
690
|
-
},
|
|
691
|
-
createdAt: {
|
|
692
|
-
type: Date,
|
|
693
|
-
required: true,
|
|
694
|
-
default: Date.now,
|
|
695
|
-
index: true
|
|
696
|
-
},
|
|
697
|
-
seenAt: {
|
|
698
|
-
type: Date,
|
|
699
|
-
required: false,
|
|
700
|
-
index: true
|
|
701
|
-
},
|
|
702
|
-
readAt: {
|
|
703
|
-
type: Date,
|
|
704
|
-
required: false,
|
|
705
|
-
index: true
|
|
706
|
-
},
|
|
707
|
-
archivedAt: {
|
|
708
|
-
type: Date,
|
|
709
|
-
required: false
|
|
710
|
-
},
|
|
711
|
-
metadata: {
|
|
712
|
-
type: Schema$1.Types.Mixed,
|
|
713
|
-
required: false
|
|
714
|
-
}
|
|
715
|
-
}, {
|
|
716
|
-
versionKey: false
|
|
610
|
+
uploadId: 1,
|
|
611
|
+
index: 1
|
|
612
|
+
}, { unique: true });
|
|
613
|
+
RBUploadChunkSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
|
|
614
|
+
//#endregion
|
|
615
|
+
//#region src/models/RBNotification.ts
|
|
616
|
+
var ZRBNotification = z$1.object({
|
|
617
|
+
userId: z$1.string(),
|
|
618
|
+
topic: z$1.string().optional(),
|
|
619
|
+
title: z$1.string(),
|
|
620
|
+
body: z$1.string().optional(),
|
|
621
|
+
url: z$1.string().optional(),
|
|
622
|
+
createdAt: z$1.date(),
|
|
623
|
+
seenAt: z$1.date().optional(),
|
|
624
|
+
readAt: z$1.date().optional(),
|
|
625
|
+
archivedAt: z$1.date().optional(),
|
|
626
|
+
metadata: z$1.record(z$1.string(), z$1.unknown()).optional()
|
|
717
627
|
});
|
|
628
|
+
var TTL_90_DAYS_S = 3600 * 24 * 90;
|
|
629
|
+
var RBNotificationSchema = new Schema$1({
|
|
630
|
+
userId: {
|
|
631
|
+
type: String,
|
|
632
|
+
required: true,
|
|
633
|
+
index: true
|
|
634
|
+
},
|
|
635
|
+
topic: {
|
|
636
|
+
type: String,
|
|
637
|
+
required: false,
|
|
638
|
+
index: true
|
|
639
|
+
},
|
|
640
|
+
title: {
|
|
641
|
+
type: String,
|
|
642
|
+
required: true
|
|
643
|
+
},
|
|
644
|
+
body: {
|
|
645
|
+
type: String,
|
|
646
|
+
required: false
|
|
647
|
+
},
|
|
648
|
+
url: {
|
|
649
|
+
type: String,
|
|
650
|
+
required: false
|
|
651
|
+
},
|
|
652
|
+
createdAt: {
|
|
653
|
+
type: Date,
|
|
654
|
+
required: true,
|
|
655
|
+
default: Date.now,
|
|
656
|
+
index: true
|
|
657
|
+
},
|
|
658
|
+
seenAt: {
|
|
659
|
+
type: Date,
|
|
660
|
+
required: false,
|
|
661
|
+
index: true
|
|
662
|
+
},
|
|
663
|
+
readAt: {
|
|
664
|
+
type: Date,
|
|
665
|
+
required: false,
|
|
666
|
+
index: true
|
|
667
|
+
},
|
|
668
|
+
archivedAt: {
|
|
669
|
+
type: Date,
|
|
670
|
+
required: false
|
|
671
|
+
},
|
|
672
|
+
metadata: {
|
|
673
|
+
type: Schema$1.Types.Mixed,
|
|
674
|
+
required: false
|
|
675
|
+
}
|
|
676
|
+
}, { versionKey: false });
|
|
718
677
|
RBNotificationSchema.index({
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
678
|
+
userId: 1,
|
|
679
|
+
archivedAt: 1,
|
|
680
|
+
createdAt: -1
|
|
722
681
|
});
|
|
723
682
|
RBNotificationSchema.index({
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
683
|
+
userId: 1,
|
|
684
|
+
seenAt: 1,
|
|
685
|
+
archivedAt: 1,
|
|
686
|
+
createdAt: -1
|
|
728
687
|
});
|
|
729
688
|
RBNotificationSchema.index({
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
689
|
+
userId: 1,
|
|
690
|
+
readAt: 1,
|
|
691
|
+
archivedAt: 1,
|
|
692
|
+
createdAt: -1
|
|
734
693
|
});
|
|
735
|
-
RBNotificationSchema.index({
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
694
|
+
RBNotificationSchema.index({ archivedAt: 1 }, { expireAfterSeconds: TTL_90_DAYS_S });
|
|
695
|
+
var RBNotificationPolicy = {
|
|
696
|
+
subject: "RBNotification",
|
|
697
|
+
define: (builder, ctx) => {
|
|
698
|
+
if (!ctx.userId) return;
|
|
699
|
+
builder.can("create", "RBNotification");
|
|
700
|
+
builder.can("read", "RBNotification", { userId: ctx.userId });
|
|
701
|
+
builder.can("update", "RBNotification", { userId: ctx.userId });
|
|
702
|
+
builder.can("delete", "RBNotification", { userId: ctx.userId });
|
|
703
|
+
}
|
|
704
|
+
};
|
|
705
|
+
//#endregion
|
|
706
|
+
//#region src/models/RBNotificationSettings.ts
|
|
707
|
+
var ZRBNotificationDigestFrequency = z$1.enum([
|
|
708
|
+
"off",
|
|
709
|
+
"daily",
|
|
710
|
+
"weekly"
|
|
711
|
+
]);
|
|
712
|
+
var ZRBNotificationTopicPreference = z$1.object({
|
|
713
|
+
topic: z$1.string(),
|
|
714
|
+
inApp: z$1.boolean(),
|
|
715
|
+
emailDigest: z$1.boolean(),
|
|
716
|
+
push: z$1.boolean()
|
|
739
717
|
});
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
builder.can("read", "RBNotification", {
|
|
746
|
-
userId: ctx.userId
|
|
747
|
-
});
|
|
748
|
-
builder.can("update", "RBNotification", {
|
|
749
|
-
userId: ctx.userId
|
|
750
|
-
});
|
|
751
|
-
builder.can("delete", "RBNotification", {
|
|
752
|
-
userId: ctx.userId
|
|
753
|
-
});
|
|
754
|
-
}
|
|
755
|
-
};
|
|
756
|
-
const ZRBNotificationDigestFrequency = z.enum(["off", "daily", "weekly"]);
|
|
757
|
-
const ZRBNotificationTopicPreference = z.object({
|
|
758
|
-
topic: z.string(),
|
|
759
|
-
inApp: z.boolean(),
|
|
760
|
-
emailDigest: z.boolean(),
|
|
761
|
-
push: z.boolean()
|
|
718
|
+
var ZRBNotificationSettings = z$1.object({
|
|
719
|
+
userId: z$1.string(),
|
|
720
|
+
digestFrequency: ZRBNotificationDigestFrequency,
|
|
721
|
+
topicPreferences: z$1.array(ZRBNotificationTopicPreference).optional(),
|
|
722
|
+
lastDigestSentAt: z$1.date().optional()
|
|
762
723
|
});
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
724
|
+
var TopicPreferenceSchema = new Schema$1({
|
|
725
|
+
topic: {
|
|
726
|
+
type: String,
|
|
727
|
+
required: true
|
|
728
|
+
},
|
|
729
|
+
inApp: {
|
|
730
|
+
type: Boolean,
|
|
731
|
+
required: true,
|
|
732
|
+
default: true
|
|
733
|
+
},
|
|
734
|
+
emailDigest: {
|
|
735
|
+
type: Boolean,
|
|
736
|
+
required: true,
|
|
737
|
+
default: true
|
|
738
|
+
},
|
|
739
|
+
push: {
|
|
740
|
+
type: Boolean,
|
|
741
|
+
required: true,
|
|
742
|
+
default: false
|
|
743
|
+
}
|
|
744
|
+
}, { _id: false });
|
|
745
|
+
var RBNotificationSettingsSchema = new Schema$1({
|
|
746
|
+
userId: {
|
|
747
|
+
type: String,
|
|
748
|
+
required: true
|
|
749
|
+
},
|
|
750
|
+
digestFrequency: {
|
|
751
|
+
type: String,
|
|
752
|
+
required: true,
|
|
753
|
+
enum: ZRBNotificationDigestFrequency.options,
|
|
754
|
+
default: "weekly"
|
|
755
|
+
},
|
|
756
|
+
topicPreferences: {
|
|
757
|
+
type: [TopicPreferenceSchema],
|
|
758
|
+
default: []
|
|
759
|
+
},
|
|
760
|
+
lastDigestSentAt: {
|
|
761
|
+
type: Date,
|
|
762
|
+
required: false
|
|
763
|
+
}
|
|
789
764
|
}, {
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
const RBNotificationSettingsSchema = new Schema$1({
|
|
793
|
-
userId: {
|
|
794
|
-
type: String,
|
|
795
|
-
required: true
|
|
796
|
-
},
|
|
797
|
-
digestFrequency: {
|
|
798
|
-
type: String,
|
|
799
|
-
required: true,
|
|
800
|
-
enum: ZRBNotificationDigestFrequency.options,
|
|
801
|
-
default: "weekly"
|
|
802
|
-
},
|
|
803
|
-
topicPreferences: {
|
|
804
|
-
type: [TopicPreferenceSchema],
|
|
805
|
-
default: []
|
|
806
|
-
},
|
|
807
|
-
lastDigestSentAt: {
|
|
808
|
-
type: Date,
|
|
809
|
-
required: false
|
|
810
|
-
}
|
|
811
|
-
}, {
|
|
812
|
-
versionKey: false,
|
|
813
|
-
timestamps: true
|
|
765
|
+
versionKey: false,
|
|
766
|
+
timestamps: true
|
|
814
767
|
});
|
|
768
|
+
RBNotificationSettingsSchema.index({ userId: 1 }, { unique: true });
|
|
815
769
|
RBNotificationSettingsSchema.index({
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
unique: true
|
|
770
|
+
userId: 1,
|
|
771
|
+
"topicPreferences.topic": 1
|
|
819
772
|
});
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
773
|
+
var RBNotificationSettingsPolicy = {
|
|
774
|
+
subject: "RBNotificationSettings",
|
|
775
|
+
define: (builder, ctx) => {
|
|
776
|
+
if (!ctx.userId) return;
|
|
777
|
+
builder.can("create", "RBNotificationSettings");
|
|
778
|
+
builder.can("read", "RBNotificationSettings", { userId: ctx.userId });
|
|
779
|
+
builder.can("update", "RBNotificationSettings", { userId: ctx.userId });
|
|
780
|
+
}
|
|
781
|
+
};
|
|
782
|
+
//#endregion
|
|
783
|
+
//#region src/models/RBOAuthRequest.ts
|
|
784
|
+
var ZRBOAuthRequest = z$1.object({
|
|
785
|
+
_id: z$1.string(),
|
|
786
|
+
providerId: z$1.string(),
|
|
787
|
+
codeVerifier: z$1.string(),
|
|
788
|
+
returnTo: z$1.string().optional(),
|
|
789
|
+
createdAt: z$1.date(),
|
|
790
|
+
expiresAt: z$1.date()
|
|
823
791
|
});
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
792
|
+
var RBOAuthRequestSchema = new Schema$1({
|
|
793
|
+
_id: {
|
|
794
|
+
type: String,
|
|
795
|
+
required: true
|
|
796
|
+
},
|
|
797
|
+
providerId: {
|
|
798
|
+
type: String,
|
|
799
|
+
required: true,
|
|
800
|
+
index: true
|
|
801
|
+
},
|
|
802
|
+
codeVerifier: {
|
|
803
|
+
type: String,
|
|
804
|
+
required: true
|
|
805
|
+
},
|
|
806
|
+
returnTo: {
|
|
807
|
+
type: String,
|
|
808
|
+
required: false
|
|
809
|
+
},
|
|
810
|
+
createdAt: {
|
|
811
|
+
type: Date,
|
|
812
|
+
required: true,
|
|
813
|
+
default: Date.now
|
|
814
|
+
},
|
|
815
|
+
expiresAt: {
|
|
816
|
+
type: Date,
|
|
817
|
+
required: true
|
|
818
|
+
}
|
|
819
|
+
}, { versionKey: false });
|
|
820
|
+
RBOAuthRequestSchema.index({ expiresAt: 1 }, { expireAfterSeconds: 0 });
|
|
821
|
+
//#endregion
|
|
822
|
+
//#region src/models/index.ts
|
|
823
|
+
var models_exports = /* @__PURE__ */ __exportAll({
|
|
824
|
+
RBNotificationPolicy: () => RBNotificationPolicy,
|
|
825
|
+
RBNotificationSchema: () => RBNotificationSchema,
|
|
826
|
+
RBNotificationSettingsPolicy: () => RBNotificationSettingsPolicy,
|
|
827
|
+
RBNotificationSettingsSchema: () => RBNotificationSettingsSchema,
|
|
828
|
+
RBOAuthRequestSchema: () => RBOAuthRequestSchema,
|
|
829
|
+
RBRtsChangeSchema: () => RBRtsChangeSchema,
|
|
830
|
+
RBRtsCounterSchema: () => RBRtsCounterSchema,
|
|
831
|
+
RBTenantSchema: () => RBTenantSchema,
|
|
832
|
+
RBTenantSubscriptionEventSchema: () => RBTenantSubscriptionEventSchema,
|
|
833
|
+
RBTenantSubscriptionSchema: () => RBTenantSubscriptionSchema,
|
|
834
|
+
RBUploadChunkSchema: () => RBUploadChunkSchema,
|
|
835
|
+
RBUploadSessionPolicy: () => RBUploadSessionPolicy,
|
|
836
|
+
RBUploadSessionSchema: () => RBUploadSessionSchema,
|
|
837
|
+
RBUserSchema: () => RBUserSchema,
|
|
838
|
+
ZRBNotification: () => ZRBNotification,
|
|
839
|
+
ZRBNotificationDigestFrequency: () => ZRBNotificationDigestFrequency,
|
|
840
|
+
ZRBNotificationSettings: () => ZRBNotificationSettings,
|
|
841
|
+
ZRBNotificationTopicPreference: () => ZRBNotificationTopicPreference,
|
|
842
|
+
ZRBOAuthRequest: () => ZRBOAuthRequest,
|
|
843
|
+
ZRBRtsChange: () => ZRBRtsChange,
|
|
844
|
+
ZRBRtsChangeOp: () => ZRBRtsChangeOp,
|
|
845
|
+
ZRBRtsCounter: () => ZRBRtsCounter,
|
|
846
|
+
ZRBTenant: () => ZRBTenant,
|
|
847
|
+
ZRBTenantSubscription: () => ZRBTenantSubscription,
|
|
848
|
+
ZRBTenantSubscriptionChangeDirection: () => ZRBTenantSubscriptionChangeDirection,
|
|
849
|
+
ZRBTenantSubscriptionEvent: () => ZRBTenantSubscriptionEvent,
|
|
850
|
+
ZRBTenantSubscriptionEventSource: () => ZRBTenantSubscriptionEventSource,
|
|
851
|
+
ZRBTenantSubscriptionIntervalUnit: () => ZRBTenantSubscriptionIntervalUnit,
|
|
852
|
+
ZRBTenantSubscriptionScope: () => ZRBTenantSubscriptionScope,
|
|
853
|
+
ZRBTenantSubscriptionStatus: () => ZRBTenantSubscriptionStatus,
|
|
854
|
+
ZRBTenantSubscriptionType: () => ZRBTenantSubscriptionType,
|
|
855
|
+
ZRBUploadChunk: () => ZRBUploadChunk,
|
|
856
|
+
ZRBUploadSession: () => ZRBUploadSession,
|
|
857
|
+
ZRBUploadSessionStatus: () => ZRBUploadSessionStatus,
|
|
858
|
+
ZRBUser: () => ZRBUser
|
|
874
859
|
});
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
}, {
|
|
878
|
-
expireAfterSeconds: 0
|
|
879
|
-
});
|
|
880
|
-
const frameworkSchemas = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
881
|
-
__proto__: null,
|
|
882
|
-
RBNotificationPolicy,
|
|
883
|
-
RBNotificationSchema,
|
|
884
|
-
RBNotificationSettingsPolicy,
|
|
885
|
-
RBNotificationSettingsSchema,
|
|
886
|
-
RBOAuthRequestSchema,
|
|
887
|
-
RBRtsChangeSchema,
|
|
888
|
-
RBRtsCounterSchema,
|
|
889
|
-
RBTenantSchema,
|
|
890
|
-
RBTenantSubscriptionEventSchema,
|
|
891
|
-
RBTenantSubscriptionSchema,
|
|
892
|
-
RBUploadChunkSchema,
|
|
893
|
-
RBUploadSessionPolicy,
|
|
894
|
-
RBUploadSessionSchema,
|
|
895
|
-
RBUserSchema,
|
|
896
|
-
ZRBNotification,
|
|
897
|
-
ZRBNotificationDigestFrequency,
|
|
898
|
-
ZRBNotificationSettings,
|
|
899
|
-
ZRBNotificationTopicPreference,
|
|
900
|
-
ZRBOAuthRequest,
|
|
901
|
-
ZRBRtsChange,
|
|
902
|
-
ZRBRtsChangeOp,
|
|
903
|
-
ZRBRtsCounter,
|
|
904
|
-
ZRBTenant,
|
|
905
|
-
ZRBTenantSubscription,
|
|
906
|
-
ZRBTenantSubscriptionChangeDirection,
|
|
907
|
-
ZRBTenantSubscriptionEvent,
|
|
908
|
-
ZRBTenantSubscriptionEventSource,
|
|
909
|
-
ZRBTenantSubscriptionIntervalUnit,
|
|
910
|
-
ZRBTenantSubscriptionScope,
|
|
911
|
-
ZRBTenantSubscriptionStatus,
|
|
912
|
-
ZRBTenantSubscriptionType,
|
|
913
|
-
ZRBUploadChunk,
|
|
914
|
-
ZRBUploadSession,
|
|
915
|
-
ZRBUploadSessionStatus,
|
|
916
|
-
ZRBUser
|
|
917
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
860
|
+
//#endregion
|
|
861
|
+
//#region src/mongoose/extendMongooseSchema.ts
|
|
918
862
|
function extendMongooseSchema(baseSchema, ...extensions) {
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
863
|
+
const schema = baseSchema.clone();
|
|
864
|
+
extensions.forEach((extension) => schema.add(extension));
|
|
865
|
+
return schema;
|
|
922
866
|
}
|
|
923
867
|
function omitMongooseSchemaPaths(schema, paths) {
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
868
|
+
const clone = schema.clone();
|
|
869
|
+
paths.forEach((path) => clone.remove(path));
|
|
870
|
+
return clone;
|
|
927
871
|
}
|
|
872
|
+
//#endregion
|
|
873
|
+
//#region src/mongoose/localizedStringField.ts
|
|
928
874
|
function localizedStringField(options) {
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
875
|
+
const userGet = options?.get;
|
|
876
|
+
return {
|
|
877
|
+
...options,
|
|
878
|
+
type: Schema$1.Types.Mixed,
|
|
879
|
+
get: (value) => withLocalizedStringFallback(userGet ? userGet(value) : value)
|
|
880
|
+
};
|
|
935
881
|
}
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
};
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
};
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
const
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
const
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
const
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
};
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
const
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
};
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
};
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
};
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
};
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
};
|
|
1390
|
-
const
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
};
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
const
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
};
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
};
|
|
1444
|
-
const
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
const
|
|
1451
|
-
const
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
};
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
}
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
const
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
};
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
};
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
};
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
};
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
};
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
};
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
const globalKey = /* @__PURE__ */ Symbol.for("@rpcbase/db/acl/mongooseAggregateAclPatched");
|
|
1707
|
-
const globalState = globalThis;
|
|
1708
|
-
if (globalState[globalKey]) return;
|
|
1709
|
-
globalState[globalKey] = true;
|
|
1710
|
-
const AggregatePrototype = mongoose.Aggregate.prototype;
|
|
1711
|
-
if (typeof AggregatePrototype.acl === "function") return;
|
|
1712
|
-
AggregatePrototype.acl = function(ability, action = "read") {
|
|
1713
|
-
this.option({
|
|
1714
|
-
rbAcl: {
|
|
1715
|
-
ability,
|
|
1716
|
-
action
|
|
1717
|
-
}
|
|
1718
|
-
});
|
|
1719
|
-
return this;
|
|
1720
|
-
};
|
|
1721
|
-
};
|
|
1722
|
-
const createModelAclProxy = (model2, ability) => {
|
|
1723
|
-
return new Proxy(model2, {
|
|
1724
|
-
get(target, prop, receiver) {
|
|
1725
|
-
if (prop === "acl") {
|
|
1726
|
-
return () => {
|
|
1727
|
-
throw new Error(`Model "${target.modelName}" is already ACL-scoped. Do not call .acl(...) again.`);
|
|
1728
|
-
};
|
|
1729
|
-
}
|
|
1730
|
-
const value = Reflect.get(target, prop, receiver);
|
|
1731
|
-
if (typeof value !== "function") return value;
|
|
1732
|
-
return (...args) => {
|
|
1733
|
-
const result = Reflect.apply(value, target, args);
|
|
1734
|
-
if (result && typeof result === "object" && "acl" in result && typeof result.acl === "function") {
|
|
1735
|
-
return result.acl(ability);
|
|
1736
|
-
}
|
|
1737
|
-
return result;
|
|
1738
|
-
};
|
|
1739
|
-
}
|
|
1740
|
-
});
|
|
1741
|
-
};
|
|
1742
|
-
const mongooseAclPlugin = (schema) => {
|
|
1743
|
-
patchAggregateAcl();
|
|
1744
|
-
schema.query.acl = function(ability, action) {
|
|
1745
|
-
this.setOptions({
|
|
1746
|
-
rbAcl: {
|
|
1747
|
-
ability,
|
|
1748
|
-
action
|
|
1749
|
-
}
|
|
1750
|
-
});
|
|
1751
|
-
return this;
|
|
1752
|
-
};
|
|
1753
|
-
schema.statics.acl = function(ability) {
|
|
1754
|
-
return createModelAclProxy(this, ability);
|
|
1755
|
-
};
|
|
1756
|
-
schema.pre("aggregate", function() {
|
|
1757
|
-
addAggregateAclFilter(this, "read");
|
|
1758
|
-
});
|
|
1759
|
-
schema.pre("countDocuments", function() {
|
|
1760
|
-
addQueryAclFilter(this, "read");
|
|
1761
|
-
});
|
|
1762
|
-
schema.pre("deleteMany", function() {
|
|
1763
|
-
addQueryAclFilter(this, "delete");
|
|
1764
|
-
});
|
|
1765
|
-
schema.pre("deleteOne", function() {
|
|
1766
|
-
addQueryAclFilter(this, "delete");
|
|
1767
|
-
});
|
|
1768
|
-
schema.pre("distinct", function() {
|
|
1769
|
-
addQueryAclFilter(this, "read");
|
|
1770
|
-
});
|
|
1771
|
-
schema.pre("find", function() {
|
|
1772
|
-
addQueryAclFilter(this, "read");
|
|
1773
|
-
});
|
|
1774
|
-
schema.pre("findOne", function() {
|
|
1775
|
-
addQueryAclFilter(this, "read");
|
|
1776
|
-
});
|
|
1777
|
-
schema.pre("findOneAndDelete", function() {
|
|
1778
|
-
addQueryAclFilter(this, "delete");
|
|
1779
|
-
});
|
|
1780
|
-
schema.pre("findOneAndReplace", function() {
|
|
1781
|
-
addQueryAclFilter(this, "update");
|
|
1782
|
-
});
|
|
1783
|
-
schema.pre("findOneAndUpdate", function() {
|
|
1784
|
-
addQueryAclFilter(this, "update");
|
|
1785
|
-
});
|
|
1786
|
-
schema.pre("replaceOne", function() {
|
|
1787
|
-
addQueryAclFilter(this, "update");
|
|
1788
|
-
});
|
|
1789
|
-
schema.pre("updateMany", function() {
|
|
1790
|
-
addQueryAclFilter(this, "update");
|
|
1791
|
-
});
|
|
1792
|
-
schema.pre("updateOne", function() {
|
|
1793
|
-
addQueryAclFilter(this, "update");
|
|
1794
|
-
});
|
|
1795
|
-
};
|
|
1796
|
-
let cachedModels = null;
|
|
1797
|
-
const DEFAULT_GLOBAL_RB_MODEL_NAMES_SET = /* @__PURE__ */ new Set(["RBUser", "RBTenant", "RBOAuthRequest"]);
|
|
1798
|
-
const assertSchema = (exportName, value) => {
|
|
1799
|
-
if (value instanceof mongoose.Schema) return value;
|
|
1800
|
-
throw new Error([`Expected ${exportName} to be an instance of mongoose.Schema, but it was not.`, "rpcbase supports mongoose 9+ only.", "Fix: ensure the project is using mongoose 9.x and that all packages resolve the same mongoose instance (try `npm ls mongoose`)."].join(" "));
|
|
1801
|
-
};
|
|
1802
|
-
const getFrameworkSchemaForModelName = (modelName) => {
|
|
1803
|
-
const exportName = `${modelName}Schema`;
|
|
1804
|
-
const value = frameworkSchemas[exportName];
|
|
1805
|
-
if (!(value instanceof mongoose.Schema)) return null;
|
|
1806
|
-
return value;
|
|
1807
|
-
};
|
|
1808
|
-
const applyTenantPlugins = (schema) => {
|
|
1809
|
-
schema.plugin(accessibleRecordsPlugin);
|
|
1810
|
-
schema.plugin(mongooseAclPlugin);
|
|
1811
|
-
schema.plugin(mongoPaginationPlugin);
|
|
1812
|
-
schema.plugin(rtsChangeLogPlugin);
|
|
1813
|
-
};
|
|
1814
|
-
const registerSchema = (target, other, modelName, schema, scope) => {
|
|
1815
|
-
if (target[modelName] || other[modelName]) {
|
|
1816
|
-
throw new Error(`Duplicate model name "${modelName}" across tenant/global scopes`);
|
|
1817
|
-
}
|
|
1818
|
-
target[modelName] = schema;
|
|
1819
|
-
};
|
|
1820
|
-
const buildSchemasFromModules = (modules) => Object.entries(modules).filter(([key]) => key.endsWith("Schema")).map(([key, schemaValue]) => {
|
|
1821
|
-
const schema = assertSchema(key, schemaValue);
|
|
1822
|
-
const modelName = key.replace(/Schema$/, "");
|
|
1823
|
-
return {
|
|
1824
|
-
modelName,
|
|
1825
|
-
schema
|
|
1826
|
-
};
|
|
1827
|
-
});
|
|
1828
|
-
const registerModels = ({
|
|
1829
|
-
tenant,
|
|
1830
|
-
global
|
|
1831
|
-
}) => {
|
|
1832
|
-
registerPoliciesFromModules(frameworkSchemas);
|
|
1833
|
-
registerPoliciesFromModules(tenant);
|
|
1834
|
-
const tenantSchemas = {};
|
|
1835
|
-
const globalSchemas = {};
|
|
1836
|
-
for (const {
|
|
1837
|
-
modelName,
|
|
1838
|
-
schema
|
|
1839
|
-
} of buildSchemasFromModules(frameworkSchemas)) {
|
|
1840
|
-
if (DEFAULT_GLOBAL_RB_MODEL_NAMES_SET.has(modelName)) {
|
|
1841
|
-
const cloned = schema.clone();
|
|
1842
|
-
registerSchema(globalSchemas, tenantSchemas, modelName, cloned);
|
|
1843
|
-
} else {
|
|
1844
|
-
const cloned = schema.clone();
|
|
1845
|
-
applyTenantPlugins(cloned);
|
|
1846
|
-
registerSchema(tenantSchemas, globalSchemas, modelName, cloned);
|
|
1847
|
-
}
|
|
1848
|
-
}
|
|
1849
|
-
for (const {
|
|
1850
|
-
modelName,
|
|
1851
|
-
schema
|
|
1852
|
-
} of buildSchemasFromModules(tenant)) {
|
|
1853
|
-
if (modelName === "RBUser" || modelName === "RBTenant") {
|
|
1854
|
-
throw new Error(`Invalid tenant model name "${modelName}". RBUser/RBTenant are global models.`);
|
|
1855
|
-
}
|
|
1856
|
-
if (modelName.startsWith("RB")) {
|
|
1857
|
-
const frameworkSchema = getFrameworkSchemaForModelName(modelName);
|
|
1858
|
-
if (frameworkSchema && schema === frameworkSchema) continue;
|
|
1859
|
-
throw new Error(`Invalid tenant model name "${modelName}". RB* models are reserved for rpcbase.`);
|
|
1860
|
-
}
|
|
1861
|
-
const cloned = schema.clone();
|
|
1862
|
-
applyTenantPlugins(cloned);
|
|
1863
|
-
registerSchema(tenantSchemas, globalSchemas, modelName, cloned);
|
|
1864
|
-
}
|
|
1865
|
-
for (const {
|
|
1866
|
-
modelName,
|
|
1867
|
-
schema
|
|
1868
|
-
} of buildSchemasFromModules(global ?? {})) {
|
|
1869
|
-
if (modelName.startsWith("RB")) {
|
|
1870
|
-
const frameworkSchema = getFrameworkSchemaForModelName(modelName);
|
|
1871
|
-
if (frameworkSchema && schema === frameworkSchema) continue;
|
|
1872
|
-
throw new Error(`Invalid global model name "${modelName}". RB* models are reserved for rpcbase.`);
|
|
1873
|
-
}
|
|
1874
|
-
const cloned = schema.clone();
|
|
1875
|
-
registerSchema(globalSchemas, tenantSchemas, modelName, cloned);
|
|
1876
|
-
}
|
|
1877
|
-
const allSchemas = {
|
|
1878
|
-
...globalSchemas,
|
|
1879
|
-
...tenantSchemas
|
|
1880
|
-
};
|
|
1881
|
-
for (const [modelName, schema] of Object.entries(allSchemas)) {
|
|
1882
|
-
if (!mongoose.models[modelName]) {
|
|
1883
|
-
mongoose.model(modelName, schema);
|
|
1884
|
-
}
|
|
1885
|
-
}
|
|
1886
|
-
cachedModels = {
|
|
1887
|
-
tenant: {
|
|
1888
|
-
...cachedModels?.tenant ?? {},
|
|
1889
|
-
...tenantSchemas
|
|
1890
|
-
},
|
|
1891
|
-
global: {
|
|
1892
|
-
...cachedModels?.global ?? {},
|
|
1893
|
-
...globalSchemas
|
|
1894
|
-
}
|
|
1895
|
-
};
|
|
1896
|
-
};
|
|
1897
|
-
const getRegisteredModels = (scope) => {
|
|
1898
|
-
if (!cachedModels) {
|
|
1899
|
-
throw new Error("Models not registered. Call createModels(...) once at startup (or import your models module) before using models.get.");
|
|
1900
|
-
}
|
|
1901
|
-
return cachedModels[scope];
|
|
1902
|
-
};
|
|
1903
|
-
const loadModelFromDb = async (modelName, dbName, scope) => {
|
|
1904
|
-
const schemas = getRegisteredModels(scope);
|
|
1905
|
-
const schema = schemas[modelName];
|
|
1906
|
-
assert(schema, `Model ${modelName} not registered. Available models: ${Object.keys(schemas).join(", ")}`);
|
|
1907
|
-
const modelConnection = await ensureMongooseConnection(dbName);
|
|
1908
|
-
if (!modelConnection.models[modelName]) {
|
|
1909
|
-
modelConnection.model(modelName, schema);
|
|
1910
|
-
}
|
|
1911
|
-
return modelConnection.models[modelName];
|
|
1912
|
-
};
|
|
1913
|
-
const normalizeTenantId$1 = (value) => {
|
|
1914
|
-
if (typeof value !== "string") return null;
|
|
1915
|
-
const tenantId = value.trim();
|
|
1916
|
-
return tenantId || null;
|
|
1917
|
-
};
|
|
1918
|
-
const getTenantIdFromLoadModelCtx = (ctx) => {
|
|
1919
|
-
const tenantId = normalizeTenantId$1(ctx.tenantId) ?? normalizeTenantId$1(ctx.req?.session?.user?.currentTenantId);
|
|
1920
|
-
assert(tenantId, "Tenant ID is missing from ctx (expected ctx.tenantId or ctx.req.session.user.currentTenantId)");
|
|
1921
|
-
return tenantId;
|
|
1922
|
-
};
|
|
1923
|
-
const models = {
|
|
1924
|
-
register: registerModels,
|
|
1925
|
-
getUnsafe: async (modelName, ctx) => {
|
|
1926
|
-
const tenantId = getTenantIdFromLoadModelCtx(ctx);
|
|
1927
|
-
const dbName = getTenantDbName(tenantId);
|
|
1928
|
-
return loadModelFromDb(modelName, dbName, "tenant");
|
|
1929
|
-
},
|
|
1930
|
-
get: async (modelName, ctx) => {
|
|
1931
|
-
const model2 = await models.getUnsafe(modelName, ctx);
|
|
1932
|
-
const resolvedAbility = ctx.ability;
|
|
1933
|
-
const isProtected = hasRegisteredPolicy(modelName);
|
|
1934
|
-
if (!isProtected) {
|
|
1935
|
-
return model2;
|
|
1936
|
-
}
|
|
1937
|
-
if (!resolvedAbility) {
|
|
1938
|
-
throw new Error(`Model "${modelName}" is ACL-protected. Set ctx.ability or use models.getUnsafe(...) explicitly.`);
|
|
1939
|
-
}
|
|
1940
|
-
if (typeof model2.acl !== "function") return model2;
|
|
1941
|
-
return model2.acl(resolvedAbility);
|
|
1942
|
-
},
|
|
1943
|
-
getGlobal: async (modelName, ctx) => {
|
|
1944
|
-
const dbName = getGlobalDbName();
|
|
1945
|
-
return loadModelFromDb(modelName, dbName, "global");
|
|
1946
|
-
}
|
|
1947
|
-
};
|
|
1948
|
-
const createModels = (modules) => {
|
|
1949
|
-
registerModels(modules);
|
|
1950
|
-
const get = (async (modelNameOrNames, ctx) => {
|
|
1951
|
-
if (Array.isArray(modelNameOrNames)) {
|
|
1952
|
-
return Promise.all(modelNameOrNames.map((modelName) => models.get(modelName, ctx)));
|
|
1953
|
-
}
|
|
1954
|
-
return models.get(modelNameOrNames, ctx);
|
|
1955
|
-
});
|
|
1956
|
-
const getUnsafe = (async (modelNameOrNames, ctx) => {
|
|
1957
|
-
if (Array.isArray(modelNameOrNames)) {
|
|
1958
|
-
return Promise.all(modelNameOrNames.map((modelName) => models.getUnsafe(modelName, ctx)));
|
|
1959
|
-
}
|
|
1960
|
-
return models.getUnsafe(modelNameOrNames, ctx);
|
|
1961
|
-
});
|
|
1962
|
-
const getGlobal = (async (modelNameOrNames, ctx) => {
|
|
1963
|
-
if (Array.isArray(modelNameOrNames)) {
|
|
1964
|
-
return Promise.all(modelNameOrNames.map((modelName) => models.getGlobal(modelName, ctx)));
|
|
1965
|
-
}
|
|
1966
|
-
return models.getGlobal(modelNameOrNames, ctx);
|
|
1967
|
-
});
|
|
1968
|
-
return {
|
|
1969
|
-
register: registerModels,
|
|
1970
|
-
get,
|
|
1971
|
-
getUnsafe,
|
|
1972
|
-
getGlobal
|
|
1973
|
-
};
|
|
1974
|
-
};
|
|
1975
|
-
const getAppName = () => {
|
|
1976
|
-
const appName = process.env.APP_NAME?.trim();
|
|
1977
|
-
assert(appName, "Missing APP_NAME");
|
|
1978
|
-
return appName;
|
|
1979
|
-
};
|
|
1980
|
-
const normalizeTenantId = (tenantId) => {
|
|
1981
|
-
const normalized = tenantId.trim();
|
|
1982
|
-
assert(normalized, "Tenant ID is missing");
|
|
1983
|
-
return normalized;
|
|
1984
|
-
};
|
|
1985
|
-
const getTenantFilesystemDbName = (tenantId) => `${getAppName()}-${normalizeTenantId(tenantId)}-filesystem-db`;
|
|
1986
|
-
const getTenantFilesystemDb = async (tenantId) => ensureMongooseConnection(getTenantFilesystemDbName(tenantId));
|
|
1987
|
-
const getTenantFilesystemDbFromCtx = async (ctx) => {
|
|
1988
|
-
const tenantId = getTenantIdFromLoadModelCtx(ctx);
|
|
1989
|
-
return getTenantFilesystemDb(tenantId);
|
|
1990
|
-
};
|
|
1991
|
-
const buildTenantLoadModelCtx = (tenantId) => ({
|
|
1992
|
-
req: {
|
|
1993
|
-
session: {
|
|
1994
|
-
user: {
|
|
1995
|
-
currentTenantId: tenantId
|
|
1996
|
-
}
|
|
1997
|
-
}
|
|
1998
|
-
}
|
|
882
|
+
//#endregion
|
|
883
|
+
//#region src/mongoose/index.ts
|
|
884
|
+
var { Schema, model } = mongoose;
|
|
885
|
+
//#endregion
|
|
886
|
+
//#region src/pagination/errors.ts
|
|
887
|
+
var PaginationValidationError = class extends Error {
|
|
888
|
+
code = "invalid_pagination";
|
|
889
|
+
statusCode = 400;
|
|
890
|
+
constructor(message, options) {
|
|
891
|
+
super(message, options);
|
|
892
|
+
this.name = "PaginationValidationError";
|
|
893
|
+
}
|
|
894
|
+
};
|
|
895
|
+
var isPaginationValidationError = (error) => {
|
|
896
|
+
if (!error || typeof error !== "object") return false;
|
|
897
|
+
const anyError = error;
|
|
898
|
+
return anyError.name === "PaginationValidationError" && anyError.code === "invalid_pagination" && anyError.statusCode === 400;
|
|
899
|
+
};
|
|
900
|
+
//#endregion
|
|
901
|
+
//#region src/pagination/normalizeSpec.ts
|
|
902
|
+
var DISALLOWED_MONGO_FIELD_SEGMENTS = new Set([
|
|
903
|
+
"__proto__",
|
|
904
|
+
"constructor",
|
|
905
|
+
"prototype"
|
|
906
|
+
]);
|
|
907
|
+
var PAGINATION_LIMIT_MAX = 128;
|
|
908
|
+
var normalizePaginationSpec = (spec) => {
|
|
909
|
+
if (!spec || typeof spec !== "object") throw new PaginationValidationError("Invalid PaginationSpec");
|
|
910
|
+
const limit = normalizeLimit(spec.limit);
|
|
911
|
+
const direction = spec.direction ?? "next";
|
|
912
|
+
if (direction !== "next" && direction !== "prev") throw new PaginationValidationError("Invalid pagination direction");
|
|
913
|
+
if (!Array.isArray(spec.sort) || spec.sort.length === 0) throw new PaginationValidationError("Invalid pagination sort");
|
|
914
|
+
const sort = spec.sort.map(({ field, order }) => ({
|
|
915
|
+
field: assertSafeMongoFieldPath(field),
|
|
916
|
+
order: normalizeOrder(order)
|
|
917
|
+
}));
|
|
918
|
+
const seenFields = /* @__PURE__ */ new Set();
|
|
919
|
+
for (const { field } of sort) {
|
|
920
|
+
if (seenFields.has(field)) throw new PaginationValidationError(`Duplicate pagination sort field: ${field}`);
|
|
921
|
+
seenFields.add(field);
|
|
922
|
+
}
|
|
923
|
+
const primaryOrder = sort[0]?.order;
|
|
924
|
+
if (!seenFields.has("_id")) sort.push({
|
|
925
|
+
field: "_id",
|
|
926
|
+
order: primaryOrder
|
|
927
|
+
});
|
|
928
|
+
return {
|
|
929
|
+
...spec,
|
|
930
|
+
limit,
|
|
931
|
+
direction,
|
|
932
|
+
sort
|
|
933
|
+
};
|
|
934
|
+
};
|
|
935
|
+
var normalizeLimit = (limit) => {
|
|
936
|
+
if (typeof limit !== "number" || !Number.isFinite(limit) || !Number.isInteger(limit) || limit <= 0) throw new PaginationValidationError("Invalid pagination limit");
|
|
937
|
+
if (limit > PAGINATION_LIMIT_MAX) throw new PaginationValidationError("Invalid pagination limit");
|
|
938
|
+
return limit;
|
|
939
|
+
};
|
|
940
|
+
var normalizeOrder = (order) => {
|
|
941
|
+
if (order !== "asc" && order !== "desc") throw new PaginationValidationError("Invalid pagination order");
|
|
942
|
+
return order;
|
|
943
|
+
};
|
|
944
|
+
var assertSafeMongoFieldPath = (field) => {
|
|
945
|
+
if (typeof field !== "string" || field.length === 0) throw new PaginationValidationError("Invalid pagination sort field");
|
|
946
|
+
if (field.startsWith("$")) throw new PaginationValidationError("Invalid pagination sort field");
|
|
947
|
+
const parts = field.split(".");
|
|
948
|
+
for (const part of parts) {
|
|
949
|
+
if (part.length === 0) throw new PaginationValidationError("Invalid pagination sort field");
|
|
950
|
+
if (DISALLOWED_MONGO_FIELD_SEGMENTS.has(part)) throw new PaginationValidationError("Invalid pagination sort field");
|
|
951
|
+
if (!/^[a-zA-Z0-9_]+$/.test(part)) throw new PaginationValidationError("Invalid pagination sort field");
|
|
952
|
+
}
|
|
953
|
+
return field;
|
|
954
|
+
};
|
|
955
|
+
//#endregion
|
|
956
|
+
//#region src/pagination/cursor.ts
|
|
957
|
+
var encodePaginationCursor = (spec, node, options) => {
|
|
958
|
+
const normalized = normalizePaginationSpec(spec);
|
|
959
|
+
const values = Object.create(null);
|
|
960
|
+
for (const { field } of normalized.sort) {
|
|
961
|
+
const value = readFieldValue(node, field);
|
|
962
|
+
if (typeof value === "undefined") throw new Error(`Pagination cursor encode failed (missing field: ${field})`);
|
|
963
|
+
values[field] = encodeCursorValue(field, value);
|
|
964
|
+
}
|
|
965
|
+
const payload = {
|
|
966
|
+
v: 1,
|
|
967
|
+
values
|
|
968
|
+
};
|
|
969
|
+
const payloadB64 = Buffer.from(JSON.stringify(payload), "utf8").toString("base64url");
|
|
970
|
+
return `${payloadB64}.${signCursorPayloadB64(payloadB64, options.signingSecret)}`;
|
|
971
|
+
};
|
|
972
|
+
var decodePaginationCursor = (spec, cursor, options) => {
|
|
973
|
+
const normalized = normalizePaginationSpec(spec);
|
|
974
|
+
const [payloadB64, sigB64, ...rest] = cursor.split(".");
|
|
975
|
+
if (rest.length > 0) throw new PaginationValidationError("Invalid pagination cursor format");
|
|
976
|
+
if (!sigB64) throw new PaginationValidationError("Invalid pagination cursor format");
|
|
977
|
+
verifyCursorSignature(payloadB64, sigB64, options.signingSecret);
|
|
978
|
+
const payloadRaw = Buffer.from(payloadB64, "base64url").toString("utf8");
|
|
979
|
+
let payloadUnknown;
|
|
980
|
+
try {
|
|
981
|
+
payloadUnknown = JSON.parse(payloadRaw);
|
|
982
|
+
} catch {
|
|
983
|
+
throw new PaginationValidationError("Invalid pagination cursor payload");
|
|
984
|
+
}
|
|
985
|
+
if (!payloadUnknown || typeof payloadUnknown !== "object") throw new PaginationValidationError("Invalid pagination cursor payload");
|
|
986
|
+
const payload = payloadUnknown;
|
|
987
|
+
if (payload.v !== 1) throw new PaginationValidationError("Unsupported pagination cursor version");
|
|
988
|
+
if (!payload.values || typeof payload.values !== "object") throw new PaginationValidationError("Invalid pagination cursor payload");
|
|
989
|
+
const decoded = Object.create(null);
|
|
990
|
+
for (const { field } of normalized.sort) {
|
|
991
|
+
if (!Object.prototype.hasOwnProperty.call(payload.values, field)) throw new PaginationValidationError(`Pagination cursor missing field: ${field}`);
|
|
992
|
+
const encodedValue = payload.values[field];
|
|
993
|
+
decoded[field] = decodeCursorValue(field, encodedValue);
|
|
994
|
+
}
|
|
995
|
+
return decoded;
|
|
996
|
+
};
|
|
997
|
+
var signCursorPayloadB64 = (payloadB64, secret) => {
|
|
998
|
+
return createHmac("sha256", secret).update(payloadB64, "utf8").digest("base64url");
|
|
999
|
+
};
|
|
1000
|
+
var verifyCursorSignature = (payloadB64, sigB64, secret) => {
|
|
1001
|
+
const expectedSigB64 = signCursorPayloadB64(payloadB64, secret);
|
|
1002
|
+
const a = Buffer.from(sigB64, "utf8");
|
|
1003
|
+
const b = Buffer.from(expectedSigB64, "utf8");
|
|
1004
|
+
if (a.length !== b.length || !timingSafeEqual(a, b)) throw new PaginationValidationError("Invalid pagination cursor signature");
|
|
1005
|
+
};
|
|
1006
|
+
var unwrapCursorComparableValue = (value) => {
|
|
1007
|
+
if (value === null || typeof value !== "object") return value;
|
|
1008
|
+
if (value instanceof Date || value instanceof Types.ObjectId) return value;
|
|
1009
|
+
let current = value;
|
|
1010
|
+
for (let depth = 0; depth < 4; depth += 1) {
|
|
1011
|
+
if (!current || typeof current !== "object") return current;
|
|
1012
|
+
if (current instanceof Date || current instanceof Types.ObjectId) return current;
|
|
1013
|
+
if (!("_id" in current)) return current;
|
|
1014
|
+
current = current._id;
|
|
1015
|
+
}
|
|
1016
|
+
return current;
|
|
1017
|
+
};
|
|
1018
|
+
var encodeCursorValue = (field, value) => {
|
|
1019
|
+
const comparableValue = unwrapCursorComparableValue(value);
|
|
1020
|
+
if (comparableValue === null) return null;
|
|
1021
|
+
if (field === "_id") {
|
|
1022
|
+
if (comparableValue instanceof Types.ObjectId) return { $oid: comparableValue.toHexString() };
|
|
1023
|
+
if (typeof comparableValue === "string") return comparableValue;
|
|
1024
|
+
throw new Error("Pagination cursor encode failed (_id must be an ObjectId or string)");
|
|
1025
|
+
}
|
|
1026
|
+
if (comparableValue instanceof Date) return { $date: comparableValue.toISOString() };
|
|
1027
|
+
if (typeof comparableValue === "string" || typeof comparableValue === "number" || typeof comparableValue === "boolean") return comparableValue;
|
|
1028
|
+
if (comparableValue instanceof Types.ObjectId) return { $oid: comparableValue.toHexString() };
|
|
1029
|
+
throw new Error(`Unsupported pagination cursor value type for field: ${field}`);
|
|
1030
|
+
};
|
|
1031
|
+
var decodeCursorValue = (field, value) => {
|
|
1032
|
+
if (value === null) return null;
|
|
1033
|
+
if (typeof value === "string") return value;
|
|
1034
|
+
if (typeof value === "number" || typeof value === "boolean") return value;
|
|
1035
|
+
if (!value || typeof value !== "object") throw new PaginationValidationError(`Invalid pagination cursor value for field: ${field}`);
|
|
1036
|
+
if ("$date" in value) {
|
|
1037
|
+
if (typeof value.$date !== "string") throw new PaginationValidationError(`Invalid pagination cursor date for field: ${field}`);
|
|
1038
|
+
const d = new Date(value.$date);
|
|
1039
|
+
if (Number.isNaN(d.getTime())) throw new PaginationValidationError(`Invalid pagination cursor date for field: ${field}`);
|
|
1040
|
+
return d;
|
|
1041
|
+
}
|
|
1042
|
+
if ("$oid" in value) {
|
|
1043
|
+
if (typeof value.$oid !== "string" || !Types.ObjectId.isValid(value.$oid)) throw new PaginationValidationError(`Invalid pagination cursor ObjectId for field: ${field}`);
|
|
1044
|
+
return new Types.ObjectId(value.$oid);
|
|
1045
|
+
}
|
|
1046
|
+
throw new PaginationValidationError(`Invalid pagination cursor value for field: ${field}`);
|
|
1047
|
+
};
|
|
1048
|
+
var readFieldValue = (node, field) => {
|
|
1049
|
+
if (!node || typeof node !== "object") return void 0;
|
|
1050
|
+
if ("get" in node && typeof node.get === "function") return node.get(field);
|
|
1051
|
+
return field.split(".").reduce((acc, key) => {
|
|
1052
|
+
if (!acc || typeof acc !== "object") return void 0;
|
|
1053
|
+
return acc[key];
|
|
1054
|
+
}, node);
|
|
1055
|
+
};
|
|
1056
|
+
//#endregion
|
|
1057
|
+
//#region src/pagination/compileMongoPagination.ts
|
|
1058
|
+
var compileMongoPagination = (spec, options) => {
|
|
1059
|
+
const normalized = normalizePaginationSpec(spec);
|
|
1060
|
+
const mongoLimit = normalized.limit + 1;
|
|
1061
|
+
const mongoSort = toMongoSort(normalized);
|
|
1062
|
+
if (normalized.cursor == null) return {
|
|
1063
|
+
spec: normalized,
|
|
1064
|
+
mongoFilterDelta: {},
|
|
1065
|
+
mongoSort,
|
|
1066
|
+
mongoLimit
|
|
1067
|
+
};
|
|
1068
|
+
if (typeof normalized.cursor !== "string" || normalized.cursor.length === 0) throw new PaginationValidationError("Invalid pagination cursor");
|
|
1069
|
+
return {
|
|
1070
|
+
spec: normalized,
|
|
1071
|
+
mongoFilterDelta: buildKeysetFilterDelta(normalized, decodePaginationCursor(normalized, normalized.cursor, options.cursor)),
|
|
1072
|
+
mongoSort,
|
|
1073
|
+
mongoLimit
|
|
1074
|
+
};
|
|
1075
|
+
};
|
|
1076
|
+
var toMongoSort = (spec) => {
|
|
1077
|
+
const mongoSort = Object.create(null);
|
|
1078
|
+
for (const { field, order } of spec.sort) mongoSort[field] = (spec.direction === "prev" ? invertOrder(order) : order) === "asc" ? 1 : -1;
|
|
1079
|
+
return mongoSort;
|
|
1080
|
+
};
|
|
1081
|
+
var buildKeysetFilterDelta = (spec, cursorValues) => {
|
|
1082
|
+
const branches = [];
|
|
1083
|
+
for (let i = 0; i < spec.sort.length; i++) {
|
|
1084
|
+
const current = spec.sort[i];
|
|
1085
|
+
if (!current) continue;
|
|
1086
|
+
const and = [];
|
|
1087
|
+
for (let j = 0; j < i; j++) {
|
|
1088
|
+
const prev = spec.sort[j];
|
|
1089
|
+
if (!prev) continue;
|
|
1090
|
+
const eq = Object.create(null);
|
|
1091
|
+
eq[prev.field] = cursorValues[prev.field];
|
|
1092
|
+
and.push(eq);
|
|
1093
|
+
}
|
|
1094
|
+
const op = getKeysetOp(current.order, spec.direction);
|
|
1095
|
+
const cmpOp = Object.create(null);
|
|
1096
|
+
cmpOp[op] = cursorValues[current.field];
|
|
1097
|
+
const cmp = Object.create(null);
|
|
1098
|
+
cmp[current.field] = cmpOp;
|
|
1099
|
+
and.push(cmp);
|
|
1100
|
+
branches.push(and.length === 1 ? and[0] : { $and: and });
|
|
1101
|
+
}
|
|
1102
|
+
return { $or: branches };
|
|
1103
|
+
};
|
|
1104
|
+
var getKeysetOp = (order, direction) => {
|
|
1105
|
+
if (direction === "next") return order === "asc" ? "$gt" : "$lt";
|
|
1106
|
+
return order === "asc" ? "$lt" : "$gt";
|
|
1107
|
+
};
|
|
1108
|
+
var invertOrder = (order) => {
|
|
1109
|
+
return order === "asc" ? "desc" : "asc";
|
|
1110
|
+
};
|
|
1111
|
+
//#endregion
|
|
1112
|
+
//#region src/pagination/materializePagination.ts
|
|
1113
|
+
var materializeMongoPagination = (compiled, fetchedNodes, options) => {
|
|
1114
|
+
const limit = compiled.spec.limit;
|
|
1115
|
+
const hasMore = fetchedNodes.length > limit;
|
|
1116
|
+
const trimmed = fetchedNodes.slice(0, limit);
|
|
1117
|
+
const nodes = compiled.spec.direction === "prev" ? trimmed.reverse() : trimmed;
|
|
1118
|
+
const hasPrevPage = compiled.spec.direction === "next" ? Boolean(compiled.spec.cursor) : hasMore;
|
|
1119
|
+
const hasNextPage = compiled.spec.direction === "next" ? hasMore : Boolean(compiled.spec.cursor);
|
|
1120
|
+
const pageInfo = {
|
|
1121
|
+
hasNextPage,
|
|
1122
|
+
hasPrevPage
|
|
1123
|
+
};
|
|
1124
|
+
if (nodes.length === 0) return {
|
|
1125
|
+
nodes,
|
|
1126
|
+
pageInfo
|
|
1127
|
+
};
|
|
1128
|
+
if (hasPrevPage) pageInfo.prevCursor = encodePaginationCursor(compiled.spec, nodes[0], options.cursor);
|
|
1129
|
+
if (hasNextPage) pageInfo.nextCursor = encodePaginationCursor(compiled.spec, nodes[nodes.length - 1], options.cursor);
|
|
1130
|
+
return {
|
|
1131
|
+
nodes,
|
|
1132
|
+
pageInfo
|
|
1133
|
+
};
|
|
1134
|
+
};
|
|
1135
|
+
//#endregion
|
|
1136
|
+
//#region src/pagination/mongoAdapter.ts
|
|
1137
|
+
var MongoAdapter = { applyPagination: (query, compiled) => {
|
|
1138
|
+
query.where(compiled.mongoFilterDelta);
|
|
1139
|
+
query.sort(compiled.mongoSort);
|
|
1140
|
+
query.limit(compiled.mongoLimit);
|
|
1141
|
+
return query;
|
|
1142
|
+
} };
|
|
1143
|
+
//#endregion
|
|
1144
|
+
//#region src/pagination/paginateMongoQuery.ts
|
|
1145
|
+
var paginateMongoQuery = async (query, pagination, options) => {
|
|
1146
|
+
const compiled = compileMongoPagination(pagination, { cursor: options.cursor });
|
|
1147
|
+
MongoAdapter.applyPagination(query, compiled);
|
|
1148
|
+
const fetchedNodes = await query.exec();
|
|
1149
|
+
if (!Array.isArray(fetchedNodes)) throw new Error("paginateMongoQuery expects query.exec() to return an array");
|
|
1150
|
+
return materializeMongoPagination(compiled, fetchedNodes, { cursor: options.cursor });
|
|
1151
|
+
};
|
|
1152
|
+
//#endregion
|
|
1153
|
+
//#region src/pagination/mongoPaginationPlugin.ts
|
|
1154
|
+
var getQueryOptions$1 = (query) => {
|
|
1155
|
+
if (!query || typeof query !== "object") return void 0;
|
|
1156
|
+
if (!("getOptions" in query) || typeof query.getOptions !== "function") return void 0;
|
|
1157
|
+
return query.getOptions();
|
|
1158
|
+
};
|
|
1159
|
+
var getPaginationFromOptions = (query) => {
|
|
1160
|
+
return getQueryOptions$1(query)?.pagination;
|
|
1161
|
+
};
|
|
1162
|
+
var getCursorFromOptions = (query) => {
|
|
1163
|
+
return getQueryOptions$1(query)?.paginationCursor;
|
|
1164
|
+
};
|
|
1165
|
+
var mongoPaginationPlugin = (schema, pluginOptions) => {
|
|
1166
|
+
schema.query.paginate = async function(pagination, options) {
|
|
1167
|
+
const spec = pagination ?? getPaginationFromOptions(this);
|
|
1168
|
+
if (!spec) throw new Error("Missing pagination spec");
|
|
1169
|
+
const cursor = options?.cursor ?? getCursorFromOptions(this) ?? pluginOptions?.cursor;
|
|
1170
|
+
if (!cursor?.signingSecret) throw new Error("Missing pagination cursor signingSecret");
|
|
1171
|
+
return await paginateMongoQuery(this, spec, { cursor });
|
|
1172
|
+
};
|
|
1173
|
+
};
|
|
1174
|
+
//#endregion
|
|
1175
|
+
//#region src/search/index.ts
|
|
1176
|
+
var buildSearchTextStage = (options) => {
|
|
1177
|
+
const index = options.index.trim();
|
|
1178
|
+
if (!index) throw new Error("Missing search index name");
|
|
1179
|
+
const query = options.query.trim();
|
|
1180
|
+
if (!query) throw new Error("Missing search query");
|
|
1181
|
+
const stage = { $search: {
|
|
1182
|
+
index,
|
|
1183
|
+
text: {
|
|
1184
|
+
query,
|
|
1185
|
+
path: options.path
|
|
1186
|
+
}
|
|
1187
|
+
} };
|
|
1188
|
+
if (options.highlightPath) stage.$search.highlight = { path: options.highlightPath };
|
|
1189
|
+
return stage;
|
|
1190
|
+
};
|
|
1191
|
+
var searchMetaProjection = () => {
|
|
1192
|
+
return {
|
|
1193
|
+
score: { $meta: "searchScore" },
|
|
1194
|
+
highlights: { $meta: "searchHighlights" }
|
|
1195
|
+
};
|
|
1196
|
+
};
|
|
1197
|
+
var listResultHasIndex = (listResult, name) => {
|
|
1198
|
+
if (!listResult || typeof listResult !== "object") return false;
|
|
1199
|
+
if (!("cursor" in listResult)) return false;
|
|
1200
|
+
const cursor = listResult.cursor;
|
|
1201
|
+
if (!cursor || typeof cursor !== "object") return false;
|
|
1202
|
+
const firstBatch = cursor.firstBatch;
|
|
1203
|
+
if (!Array.isArray(firstBatch)) return false;
|
|
1204
|
+
return firstBatch.some((idx) => idx && typeof idx === "object" && "name" in idx && idx.name === name);
|
|
1205
|
+
};
|
|
1206
|
+
var isIndexAlreadyExistsError = (error) => {
|
|
1207
|
+
if (!error || typeof error !== "object") return false;
|
|
1208
|
+
if (("codeName" in error ? error.codeName : void 0) === "IndexAlreadyExists") return true;
|
|
1209
|
+
const message = "message" in error ? String(error.message ?? "") : "";
|
|
1210
|
+
return /already exists/i.test(message);
|
|
1211
|
+
};
|
|
1212
|
+
var ensureSearchIndex = async (params) => {
|
|
1213
|
+
const collection = params.collection.trim();
|
|
1214
|
+
if (!collection) throw new Error("Missing collection name");
|
|
1215
|
+
const name = params.name.trim();
|
|
1216
|
+
if (!name) throw new Error("Missing search index name");
|
|
1217
|
+
let listResult;
|
|
1218
|
+
try {
|
|
1219
|
+
listResult = await params.db.command({ listSearchIndexes: collection });
|
|
1220
|
+
} catch (error) {
|
|
1221
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1222
|
+
throw new Error(`listSearchIndexes failed for "${collection}": ${message}`);
|
|
1223
|
+
}
|
|
1224
|
+
if (listResultHasIndex(listResult, name)) return { created: false };
|
|
1225
|
+
try {
|
|
1226
|
+
await params.db.command({
|
|
1227
|
+
createSearchIndexes: collection,
|
|
1228
|
+
indexes: [{
|
|
1229
|
+
name,
|
|
1230
|
+
definition: params.definition
|
|
1231
|
+
}]
|
|
1232
|
+
});
|
|
1233
|
+
} catch (error) {
|
|
1234
|
+
if (isIndexAlreadyExistsError(error)) return { created: false };
|
|
1235
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1236
|
+
throw new Error(`createSearchIndexes failed for "${collection}" (index "${name}"): ${message}`);
|
|
1237
|
+
}
|
|
1238
|
+
return { created: true };
|
|
1239
|
+
};
|
|
1240
|
+
//#endregion
|
|
1241
|
+
//#region src/dbNames.ts
|
|
1242
|
+
var getAppName$1 = (env = process.env) => {
|
|
1243
|
+
const appName = env.APP_NAME?.trim();
|
|
1244
|
+
if (!appName) throw new Error("Missing APP_NAME");
|
|
1245
|
+
return appName;
|
|
1246
|
+
};
|
|
1247
|
+
var GLOBAL_DB_SUFFIX = "-global-db";
|
|
1248
|
+
var getGlobalDbName = (env = process.env) => {
|
|
1249
|
+
return `${getAppName$1(env)}${GLOBAL_DB_SUFFIX}`;
|
|
1250
|
+
};
|
|
1251
|
+
var getTenantDbName = (tenantId, env = process.env) => {
|
|
1252
|
+
return `${getAppName$1(env)}-${tenantId.trim()}-db`;
|
|
1253
|
+
};
|
|
1254
|
+
//#endregion
|
|
1255
|
+
//#region src/getMongoUrl.ts
|
|
1256
|
+
var getMongoUrl = (env = process.env) => {
|
|
1257
|
+
const explicitUrl = env.MONGODB_URL ?? env.MONGO_URL ?? env.MONGODB_URI ?? env.DB_URL;
|
|
1258
|
+
if (explicitUrl && explicitUrl.trim()) return explicitUrl.trim();
|
|
1259
|
+
const port = env.DB_PORT?.trim();
|
|
1260
|
+
if (!port) throw new Error("Missing Mongo connection details (MONGODB_URL/MONGO_URL/MONGODB_URI/DB_URL/DB_PORT)");
|
|
1261
|
+
return `mongodb://${env.DB_HOST?.trim() || "localhost"}:${port}`;
|
|
1262
|
+
};
|
|
1263
|
+
//#endregion
|
|
1264
|
+
//#region src/ensureMongooseConnection.ts
|
|
1265
|
+
var connections = /* @__PURE__ */ new Map();
|
|
1266
|
+
var rootConnection = null;
|
|
1267
|
+
var CONNECTION_MAX_LISTENERS = 50;
|
|
1268
|
+
var waitForOpen = async (connection) => {
|
|
1269
|
+
if (connection.readyState === 1) return;
|
|
1270
|
+
if (connection.getMaxListeners() < CONNECTION_MAX_LISTENERS) connection.setMaxListeners(CONNECTION_MAX_LISTENERS);
|
|
1271
|
+
await new Promise((resolve, reject) => {
|
|
1272
|
+
connection.once("open", resolve);
|
|
1273
|
+
connection.once("error", reject);
|
|
1274
|
+
});
|
|
1275
|
+
};
|
|
1276
|
+
var ensureMongooseConnection = async (dbName) => {
|
|
1277
|
+
const normalizedDbName = dbName.trim();
|
|
1278
|
+
if (!normalizedDbName) throw new Error("Missing dbName");
|
|
1279
|
+
const existing = connections.get(normalizedDbName);
|
|
1280
|
+
if (existing) {
|
|
1281
|
+
await waitForOpen(existing);
|
|
1282
|
+
return existing;
|
|
1283
|
+
}
|
|
1284
|
+
if (!rootConnection) {
|
|
1285
|
+
const mongoUrl = getMongoUrl();
|
|
1286
|
+
rootConnection = mongoose$1.createConnection(mongoUrl, {
|
|
1287
|
+
sanitizeFilter: true,
|
|
1288
|
+
dbName: normalizedDbName
|
|
1289
|
+
});
|
|
1290
|
+
}
|
|
1291
|
+
await waitForOpen(rootConnection);
|
|
1292
|
+
const connection = rootConnection.name === normalizedDbName ? rootConnection : rootConnection.useDb(normalizedDbName, { useCache: true });
|
|
1293
|
+
await waitForOpen(connection);
|
|
1294
|
+
connections.set(normalizedDbName, connection);
|
|
1295
|
+
return connection;
|
|
1296
|
+
};
|
|
1297
|
+
//#endregion
|
|
1298
|
+
//#region src/rtsChangeLogPlugin.ts
|
|
1299
|
+
var RTS_COUNTER_ID = "rts";
|
|
1300
|
+
var EXCLUDED_MODEL_NAMES = new Set(["RBRtsChange", "RBRtsCounter"]);
|
|
1301
|
+
var maxDeleteIdsRaw = process.env.RB_RTS_DELETE_LOG_MAX_IDS ?? "";
|
|
1302
|
+
var maxDeleteIds = Number.isFinite(Number(maxDeleteIdsRaw)) ? Math.max(1, Math.floor(Number(maxDeleteIdsRaw))) : 5e3;
|
|
1303
|
+
var deleteMetaByQuery = /* @__PURE__ */ new WeakMap();
|
|
1304
|
+
var hasToString = (value) => {
|
|
1305
|
+
if (typeof value !== "object" || value === null) return false;
|
|
1306
|
+
return typeof value.toString === "function";
|
|
1307
|
+
};
|
|
1308
|
+
var normalizeId = (id) => {
|
|
1309
|
+
if (!id) return null;
|
|
1310
|
+
if (typeof id === "string") return id;
|
|
1311
|
+
if (hasToString(id)) return id.toString();
|
|
1312
|
+
return null;
|
|
1313
|
+
};
|
|
1314
|
+
var getDbName = (db) => {
|
|
1315
|
+
if (!db || typeof db !== "object") return "";
|
|
1316
|
+
const maybe = db;
|
|
1317
|
+
const raw = maybe.name ?? maybe.db?.databaseName;
|
|
1318
|
+
return typeof raw === "string" ? raw : "";
|
|
1319
|
+
};
|
|
1320
|
+
var isGlobalDb = (db) => getDbName(db).endsWith(GLOBAL_DB_SUFFIX);
|
|
1321
|
+
var getQuerySession = (query) => {
|
|
1322
|
+
const opts = typeof query.getOptions === "function" ? query.getOptions() : void 0;
|
|
1323
|
+
if (!opts || typeof opts !== "object") return void 0;
|
|
1324
|
+
const session = opts.session;
|
|
1325
|
+
if (!session || typeof session !== "object") return void 0;
|
|
1326
|
+
return session;
|
|
1327
|
+
};
|
|
1328
|
+
var getRtsModels = (db) => {
|
|
1329
|
+
return {
|
|
1330
|
+
RtsCounter: db.models.RBRtsCounter ?? db.model("RBRtsCounter", RBRtsCounterSchema),
|
|
1331
|
+
RtsChange: db.models.RBRtsChange ?? db.model("RBRtsChange", RBRtsChangeSchema)
|
|
1332
|
+
};
|
|
1333
|
+
};
|
|
1334
|
+
var allocateSeqRange = async (db, count, session) => {
|
|
1335
|
+
const { RtsCounter } = getRtsModels(db);
|
|
1336
|
+
const updated = await RtsCounter.findOneAndUpdate({ _id: RTS_COUNTER_ID }, { $inc: { seq: count } }, {
|
|
1337
|
+
upsert: true,
|
|
1338
|
+
returnDocument: "after",
|
|
1339
|
+
setDefaultsOnInsert: true,
|
|
1340
|
+
projection: { seq: 1 },
|
|
1341
|
+
session
|
|
1342
|
+
}).lean();
|
|
1343
|
+
const end = Number(updated?.seq ?? 0);
|
|
1344
|
+
return {
|
|
1345
|
+
start: end - count + 1,
|
|
1346
|
+
end
|
|
1347
|
+
};
|
|
1348
|
+
};
|
|
1349
|
+
var insertChanges = async (db, changes, session) => {
|
|
1350
|
+
if (!changes.length) return;
|
|
1351
|
+
const { RtsChange } = getRtsModels(db);
|
|
1352
|
+
const ts = /* @__PURE__ */ new Date();
|
|
1353
|
+
const docs = changes.map((c) => ({
|
|
1354
|
+
seq: c.seq,
|
|
1355
|
+
modelName: c.modelName,
|
|
1356
|
+
op: c.op,
|
|
1357
|
+
docId: c.docId ?? void 0,
|
|
1358
|
+
ts
|
|
1359
|
+
}));
|
|
1360
|
+
if (session) {
|
|
1361
|
+
await RtsChange.insertMany(docs, { session });
|
|
1362
|
+
return;
|
|
1363
|
+
}
|
|
1364
|
+
await RtsChange.insertMany(docs);
|
|
1365
|
+
};
|
|
1366
|
+
var recordDeleteChanges = async (db, modelName, ids, session) => {
|
|
1367
|
+
const uniqueIds = Array.from(new Set(ids)).filter(Boolean);
|
|
1368
|
+
if (!uniqueIds.length) return;
|
|
1369
|
+
const { start } = await allocateSeqRange(db, uniqueIds.length, session);
|
|
1370
|
+
await insertChanges(db, uniqueIds.map((docId, idx) => ({
|
|
1371
|
+
seq: start + idx,
|
|
1372
|
+
modelName,
|
|
1373
|
+
op: "delete",
|
|
1374
|
+
docId
|
|
1375
|
+
})), session);
|
|
1376
|
+
};
|
|
1377
|
+
var recordResetModel = async (db, modelName, session) => {
|
|
1378
|
+
const { start } = await allocateSeqRange(db, 1, session);
|
|
1379
|
+
await insertChanges(db, [{
|
|
1380
|
+
seq: start,
|
|
1381
|
+
modelName,
|
|
1382
|
+
op: "reset_model"
|
|
1383
|
+
}], session);
|
|
1384
|
+
};
|
|
1385
|
+
var captureDeleteMeta = async (query, mode) => {
|
|
1386
|
+
const modelName = String(query?.model?.modelName ?? "");
|
|
1387
|
+
if (!modelName || modelName.startsWith("RB") || EXCLUDED_MODEL_NAMES.has(modelName)) return;
|
|
1388
|
+
if (isGlobalDb(query?.model?.db)) return;
|
|
1389
|
+
const filter = typeof query.getFilter === "function" ? query.getFilter() : query.getQuery?.() ?? {};
|
|
1390
|
+
const session = getQuerySession(query);
|
|
1391
|
+
const findQuery = query.model.find(filter, { _id: 1 });
|
|
1392
|
+
if (session && typeof findQuery.session === "function") findQuery.session(session);
|
|
1393
|
+
findQuery.lean();
|
|
1394
|
+
if (mode === "one") findQuery.limit(1);
|
|
1395
|
+
else findQuery.limit(maxDeleteIds + 1);
|
|
1396
|
+
const docs = await findQuery;
|
|
1397
|
+
const ids = Array.isArray(docs) ? docs.map((d) => normalizeId(d?._id)).filter((id) => Boolean(id)) : [];
|
|
1398
|
+
const reset = mode === "many" && ids.length > maxDeleteIds;
|
|
1399
|
+
const meta = {
|
|
1400
|
+
modelName,
|
|
1401
|
+
ids: reset ? [] : ids,
|
|
1402
|
+
reset,
|
|
1403
|
+
session
|
|
1404
|
+
};
|
|
1405
|
+
deleteMetaByQuery.set(query, meta);
|
|
1406
|
+
};
|
|
1407
|
+
var flushDeleteMeta = async (query) => {
|
|
1408
|
+
const meta = deleteMetaByQuery.get(query);
|
|
1409
|
+
deleteMetaByQuery.delete(query);
|
|
1410
|
+
if (!meta) return;
|
|
1411
|
+
const db = query?.model?.db;
|
|
1412
|
+
if (!db) return;
|
|
1413
|
+
try {
|
|
1414
|
+
if (meta.reset) await recordResetModel(db, meta.modelName, meta.session);
|
|
1415
|
+
else await recordDeleteChanges(db, meta.modelName, meta.ids, meta.session);
|
|
1416
|
+
} catch {
|
|
1417
|
+
return;
|
|
1418
|
+
}
|
|
1419
|
+
};
|
|
1420
|
+
var rtsChangeLogPlugin = (schema) => {
|
|
1421
|
+
schema.pre("deleteOne", {
|
|
1422
|
+
query: true,
|
|
1423
|
+
document: false
|
|
1424
|
+
}, async function() {
|
|
1425
|
+
await captureDeleteMeta(this, "one");
|
|
1426
|
+
});
|
|
1427
|
+
schema.pre("deleteMany", {
|
|
1428
|
+
query: true,
|
|
1429
|
+
document: false
|
|
1430
|
+
}, async function() {
|
|
1431
|
+
await captureDeleteMeta(this, "many");
|
|
1432
|
+
});
|
|
1433
|
+
schema.post("deleteOne", {
|
|
1434
|
+
query: true,
|
|
1435
|
+
document: false
|
|
1436
|
+
}, async function() {
|
|
1437
|
+
await flushDeleteMeta(this);
|
|
1438
|
+
});
|
|
1439
|
+
schema.post("deleteMany", {
|
|
1440
|
+
query: true,
|
|
1441
|
+
document: false
|
|
1442
|
+
}, async function() {
|
|
1443
|
+
await flushDeleteMeta(this);
|
|
1444
|
+
});
|
|
1445
|
+
schema.post("findOneAndDelete", {
|
|
1446
|
+
query: true,
|
|
1447
|
+
document: false
|
|
1448
|
+
}, async function(doc) {
|
|
1449
|
+
const modelName = String(this?.model?.modelName ?? "");
|
|
1450
|
+
if (!modelName || modelName.startsWith("RB") || EXCLUDED_MODEL_NAMES.has(modelName)) return;
|
|
1451
|
+
const db = this?.model?.db;
|
|
1452
|
+
if (!db) return;
|
|
1453
|
+
if (isGlobalDb(db)) return;
|
|
1454
|
+
const docId = normalizeId(doc?._id);
|
|
1455
|
+
if (!docId) return;
|
|
1456
|
+
try {
|
|
1457
|
+
const session = getQuerySession(this);
|
|
1458
|
+
await recordDeleteChanges(db, modelName, [docId], session);
|
|
1459
|
+
} catch {
|
|
1460
|
+
return;
|
|
1461
|
+
}
|
|
1462
|
+
});
|
|
1463
|
+
};
|
|
1464
|
+
//#endregion
|
|
1465
|
+
//#region src/acl/mongooseAclPlugin.ts
|
|
1466
|
+
var isRecord = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
1467
|
+
var mergeMongoQuery = (left, right) => {
|
|
1468
|
+
const leftQuery = isRecord(left) ? left : {};
|
|
1469
|
+
if (Object.keys(leftQuery).length === 0) return right;
|
|
1470
|
+
if (Object.keys(right).length === 0) return leftQuery;
|
|
1471
|
+
return { $and: [leftQuery, right] };
|
|
1472
|
+
};
|
|
1473
|
+
var getQueryOptions = (query) => {
|
|
1474
|
+
if (!query || typeof query !== "object") return void 0;
|
|
1475
|
+
if (!("getOptions" in query) || typeof query.getOptions !== "function") return void 0;
|
|
1476
|
+
return query.getOptions();
|
|
1477
|
+
};
|
|
1478
|
+
var getStoredAclFromQuery = (query) => {
|
|
1479
|
+
const raw = getQueryOptions(query)?.rbAcl;
|
|
1480
|
+
if (!isRecord(raw)) return null;
|
|
1481
|
+
if (!("ability" in raw)) return null;
|
|
1482
|
+
return raw;
|
|
1483
|
+
};
|
|
1484
|
+
var getStoredAclFromAggregate = (aggregate) => {
|
|
1485
|
+
if (!aggregate || typeof aggregate !== "object") return null;
|
|
1486
|
+
const raw = aggregate.options;
|
|
1487
|
+
if (!isRecord(raw)) return null;
|
|
1488
|
+
const acl = raw.rbAcl;
|
|
1489
|
+
if (!isRecord(acl)) return null;
|
|
1490
|
+
if (!("ability" in acl)) return null;
|
|
1491
|
+
return acl;
|
|
1492
|
+
};
|
|
1493
|
+
var addQueryAclFilter = (query, action) => {
|
|
1494
|
+
const storedAcl = getStoredAclFromQuery(query);
|
|
1495
|
+
if (!storedAcl) return;
|
|
1496
|
+
const ability = storedAcl.ability;
|
|
1497
|
+
const resolvedAction = storedAcl.action ?? action;
|
|
1498
|
+
const modelName = query.model.modelName;
|
|
1499
|
+
const accessQuery = accessibleBy(ability, resolvedAction).ofType(modelName);
|
|
1500
|
+
query.and([accessQuery]);
|
|
1501
|
+
};
|
|
1502
|
+
var injectAggregateMatch = (pipeline, match) => {
|
|
1503
|
+
if (pipeline.length === 0) {
|
|
1504
|
+
pipeline.unshift({ $match: match });
|
|
1505
|
+
return;
|
|
1506
|
+
}
|
|
1507
|
+
const first = pipeline[0];
|
|
1508
|
+
if (!isRecord(first)) {
|
|
1509
|
+
pipeline.unshift({ $match: match });
|
|
1510
|
+
return;
|
|
1511
|
+
}
|
|
1512
|
+
if ("$geoNear" in first) {
|
|
1513
|
+
const geoNear = first.$geoNear;
|
|
1514
|
+
if (isRecord(geoNear)) {
|
|
1515
|
+
geoNear.query = mergeMongoQuery(geoNear.query, match);
|
|
1516
|
+
return;
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
if ("$search" in first || "$vectorSearch" in first || "$searchMeta" in first) {
|
|
1520
|
+
pipeline.splice(1, 0, { $match: match });
|
|
1521
|
+
return;
|
|
1522
|
+
}
|
|
1523
|
+
pipeline.unshift({ $match: match });
|
|
1524
|
+
};
|
|
1525
|
+
var addAggregateAclFilter = (aggregate, action) => {
|
|
1526
|
+
const storedAcl = getStoredAclFromAggregate(aggregate);
|
|
1527
|
+
if (!storedAcl) return;
|
|
1528
|
+
const ability = storedAcl.ability;
|
|
1529
|
+
const resolvedAction = storedAcl.action ?? action;
|
|
1530
|
+
const modelName = aggregate.model().modelName;
|
|
1531
|
+
const accessQuery = accessibleBy(ability, resolvedAction).ofType(modelName);
|
|
1532
|
+
injectAggregateMatch(aggregate.pipeline(), accessQuery);
|
|
1533
|
+
};
|
|
1534
|
+
var patchAggregateAcl = () => {
|
|
1535
|
+
const globalKey = Symbol.for("@rpcbase/db/acl/mongooseAggregateAclPatched");
|
|
1536
|
+
const globalState = globalThis;
|
|
1537
|
+
if (globalState[globalKey]) return;
|
|
1538
|
+
globalState[globalKey] = true;
|
|
1539
|
+
const AggregatePrototype = mongoose$1.Aggregate.prototype;
|
|
1540
|
+
if (typeof AggregatePrototype.acl === "function") return;
|
|
1541
|
+
AggregatePrototype.acl = function(ability, action = "read") {
|
|
1542
|
+
this.option({ rbAcl: {
|
|
1543
|
+
ability,
|
|
1544
|
+
action
|
|
1545
|
+
} });
|
|
1546
|
+
return this;
|
|
1547
|
+
};
|
|
1548
|
+
};
|
|
1549
|
+
var createModelAclProxy = (model, ability) => {
|
|
1550
|
+
return new Proxy(model, { get(target, prop, receiver) {
|
|
1551
|
+
if (prop === "acl") return () => {
|
|
1552
|
+
throw new Error(`Model "${target.modelName}" is already ACL-scoped. Do not call .acl(...) again.`);
|
|
1553
|
+
};
|
|
1554
|
+
const value = Reflect.get(target, prop, receiver);
|
|
1555
|
+
if (typeof value !== "function") return value;
|
|
1556
|
+
return (...args) => {
|
|
1557
|
+
const result = Reflect.apply(value, target, args);
|
|
1558
|
+
if (result && typeof result === "object" && "acl" in result && typeof result.acl === "function") return result.acl(ability);
|
|
1559
|
+
return result;
|
|
1560
|
+
};
|
|
1561
|
+
} });
|
|
1562
|
+
};
|
|
1563
|
+
var mongooseAclPlugin = (schema) => {
|
|
1564
|
+
patchAggregateAcl();
|
|
1565
|
+
schema.query.acl = function(ability, action) {
|
|
1566
|
+
this.setOptions({ rbAcl: {
|
|
1567
|
+
ability,
|
|
1568
|
+
action
|
|
1569
|
+
} });
|
|
1570
|
+
return this;
|
|
1571
|
+
};
|
|
1572
|
+
schema.statics.acl = function(ability) {
|
|
1573
|
+
return createModelAclProxy(this, ability);
|
|
1574
|
+
};
|
|
1575
|
+
schema.pre("aggregate", function() {
|
|
1576
|
+
addAggregateAclFilter(this, "read");
|
|
1577
|
+
});
|
|
1578
|
+
schema.pre("countDocuments", function() {
|
|
1579
|
+
addQueryAclFilter(this, "read");
|
|
1580
|
+
});
|
|
1581
|
+
schema.pre("deleteMany", function() {
|
|
1582
|
+
addQueryAclFilter(this, "delete");
|
|
1583
|
+
});
|
|
1584
|
+
schema.pre("deleteOne", function() {
|
|
1585
|
+
addQueryAclFilter(this, "delete");
|
|
1586
|
+
});
|
|
1587
|
+
schema.pre("distinct", function() {
|
|
1588
|
+
addQueryAclFilter(this, "read");
|
|
1589
|
+
});
|
|
1590
|
+
schema.pre("find", function() {
|
|
1591
|
+
addQueryAclFilter(this, "read");
|
|
1592
|
+
});
|
|
1593
|
+
schema.pre("findOne", function() {
|
|
1594
|
+
addQueryAclFilter(this, "read");
|
|
1595
|
+
});
|
|
1596
|
+
schema.pre("findOneAndDelete", function() {
|
|
1597
|
+
addQueryAclFilter(this, "delete");
|
|
1598
|
+
});
|
|
1599
|
+
schema.pre("findOneAndReplace", function() {
|
|
1600
|
+
addQueryAclFilter(this, "update");
|
|
1601
|
+
});
|
|
1602
|
+
schema.pre("findOneAndUpdate", function() {
|
|
1603
|
+
addQueryAclFilter(this, "update");
|
|
1604
|
+
});
|
|
1605
|
+
schema.pre("replaceOne", function() {
|
|
1606
|
+
addQueryAclFilter(this, "update");
|
|
1607
|
+
});
|
|
1608
|
+
schema.pre("updateMany", function() {
|
|
1609
|
+
addQueryAclFilter(this, "update");
|
|
1610
|
+
});
|
|
1611
|
+
schema.pre("updateOne", function() {
|
|
1612
|
+
addQueryAclFilter(this, "update");
|
|
1613
|
+
});
|
|
1614
|
+
};
|
|
1615
|
+
//#endregion
|
|
1616
|
+
//#region src/registerModels.ts
|
|
1617
|
+
var cachedModels = null;
|
|
1618
|
+
var DEFAULT_GLOBAL_RB_MODEL_NAMES_SET = new Set([
|
|
1619
|
+
"RBUser",
|
|
1620
|
+
"RBTenant",
|
|
1621
|
+
"RBOAuthRequest"
|
|
1622
|
+
]);
|
|
1623
|
+
var assertSchema = (exportName, value) => {
|
|
1624
|
+
if (value instanceof mongoose$1.Schema) return value;
|
|
1625
|
+
throw new Error([
|
|
1626
|
+
`Expected ${exportName} to be an instance of mongoose.Schema, but it was not.`,
|
|
1627
|
+
"rpcbase supports mongoose 9+ only.",
|
|
1628
|
+
"Fix: ensure the project is using mongoose 9.x and that all packages resolve the same mongoose instance (try `npm ls mongoose`)."
|
|
1629
|
+
].join(" "));
|
|
1630
|
+
};
|
|
1631
|
+
var getFrameworkSchemaForModelName = (modelName) => {
|
|
1632
|
+
const value = models_exports[`${modelName}Schema`];
|
|
1633
|
+
if (!(value instanceof mongoose$1.Schema)) return null;
|
|
1634
|
+
return value;
|
|
1635
|
+
};
|
|
1636
|
+
var applyTenantPlugins = (schema) => {
|
|
1637
|
+
schema.plugin(accessibleRecordsPlugin);
|
|
1638
|
+
schema.plugin(mongooseAclPlugin);
|
|
1639
|
+
schema.plugin(mongoPaginationPlugin);
|
|
1640
|
+
schema.plugin(rtsChangeLogPlugin);
|
|
1641
|
+
};
|
|
1642
|
+
var registerSchema = (target, other, modelName, schema, scope) => {
|
|
1643
|
+
if (target[modelName] || other[modelName]) throw new Error(`Duplicate model name "${modelName}" across tenant/global scopes`);
|
|
1644
|
+
target[modelName] = schema;
|
|
1645
|
+
};
|
|
1646
|
+
var buildSchemasFromModules = (modules) => Object.entries(modules).filter(([key]) => key.endsWith("Schema")).map(([key, schemaValue]) => {
|
|
1647
|
+
const schema = assertSchema(key, schemaValue);
|
|
1648
|
+
return {
|
|
1649
|
+
modelName: key.replace(/Schema$/, ""),
|
|
1650
|
+
schema
|
|
1651
|
+
};
|
|
1999
1652
|
});
|
|
1653
|
+
var registerModels = ({ tenant, global }) => {
|
|
1654
|
+
registerPoliciesFromModules(models_exports);
|
|
1655
|
+
registerPoliciesFromModules(tenant);
|
|
1656
|
+
const tenantSchemas = {};
|
|
1657
|
+
const globalSchemas = {};
|
|
1658
|
+
for (const { modelName, schema } of buildSchemasFromModules(models_exports)) if (DEFAULT_GLOBAL_RB_MODEL_NAMES_SET.has(modelName)) registerSchema(globalSchemas, tenantSchemas, modelName, schema.clone(), "global");
|
|
1659
|
+
else {
|
|
1660
|
+
const cloned = schema.clone();
|
|
1661
|
+
applyTenantPlugins(cloned);
|
|
1662
|
+
registerSchema(tenantSchemas, globalSchemas, modelName, cloned, "tenant");
|
|
1663
|
+
}
|
|
1664
|
+
for (const { modelName, schema } of buildSchemasFromModules(tenant)) {
|
|
1665
|
+
if (modelName === "RBUser" || modelName === "RBTenant") throw new Error(`Invalid tenant model name "${modelName}". RBUser/RBTenant are global models.`);
|
|
1666
|
+
if (modelName.startsWith("RB")) {
|
|
1667
|
+
const frameworkSchema = getFrameworkSchemaForModelName(modelName);
|
|
1668
|
+
if (frameworkSchema && schema === frameworkSchema) continue;
|
|
1669
|
+
throw new Error(`Invalid tenant model name "${modelName}". RB* models are reserved for rpcbase.`);
|
|
1670
|
+
}
|
|
1671
|
+
const cloned = schema.clone();
|
|
1672
|
+
applyTenantPlugins(cloned);
|
|
1673
|
+
registerSchema(tenantSchemas, globalSchemas, modelName, cloned, "tenant");
|
|
1674
|
+
}
|
|
1675
|
+
for (const { modelName, schema } of buildSchemasFromModules(global ?? {})) {
|
|
1676
|
+
if (modelName.startsWith("RB")) {
|
|
1677
|
+
const frameworkSchema = getFrameworkSchemaForModelName(modelName);
|
|
1678
|
+
if (frameworkSchema && schema === frameworkSchema) continue;
|
|
1679
|
+
throw new Error(`Invalid global model name "${modelName}". RB* models are reserved for rpcbase.`);
|
|
1680
|
+
}
|
|
1681
|
+
registerSchema(globalSchemas, tenantSchemas, modelName, schema.clone(), "global");
|
|
1682
|
+
}
|
|
1683
|
+
const allSchemas = {
|
|
1684
|
+
...globalSchemas,
|
|
1685
|
+
...tenantSchemas
|
|
1686
|
+
};
|
|
1687
|
+
for (const [modelName, schema] of Object.entries(allSchemas)) if (!mongoose$1.models[modelName]) mongoose$1.model(modelName, schema);
|
|
1688
|
+
cachedModels = {
|
|
1689
|
+
tenant: {
|
|
1690
|
+
...cachedModels?.tenant ?? {},
|
|
1691
|
+
...tenantSchemas
|
|
1692
|
+
},
|
|
1693
|
+
global: {
|
|
1694
|
+
...cachedModels?.global ?? {},
|
|
1695
|
+
...globalSchemas
|
|
1696
|
+
}
|
|
1697
|
+
};
|
|
1698
|
+
};
|
|
1699
|
+
var getRegisteredModels = (scope) => {
|
|
1700
|
+
if (!cachedModels) throw new Error("Models not registered. Call createModels(...) once at startup (or import your models module) before using models.get.");
|
|
1701
|
+
return cachedModels[scope];
|
|
1702
|
+
};
|
|
1703
|
+
//#endregion
|
|
1704
|
+
//#region src/modelsApi.ts
|
|
1705
|
+
var loadModelFromDb = async (modelName, dbName, scope) => {
|
|
1706
|
+
const schemas = getRegisteredModels(scope);
|
|
1707
|
+
const schema = schemas[modelName];
|
|
1708
|
+
assert(schema, `Model ${modelName} not registered. Available models: ${Object.keys(schemas).join(", ")}`);
|
|
1709
|
+
const modelConnection = await ensureMongooseConnection(dbName);
|
|
1710
|
+
if (!modelConnection.models[modelName]) modelConnection.model(modelName, schema);
|
|
1711
|
+
return modelConnection.models[modelName];
|
|
1712
|
+
};
|
|
1713
|
+
var normalizeTenantId$1 = (value) => {
|
|
1714
|
+
if (typeof value !== "string") return null;
|
|
1715
|
+
return value.trim() || null;
|
|
1716
|
+
};
|
|
1717
|
+
var getTenantIdFromLoadModelCtx = (ctx) => {
|
|
1718
|
+
const tenantId = normalizeTenantId$1(ctx.tenantId) ?? normalizeTenantId$1(ctx.req?.session?.user?.currentTenantId);
|
|
1719
|
+
assert(tenantId, "Tenant ID is missing from ctx (expected ctx.tenantId or ctx.req.session.user.currentTenantId)");
|
|
1720
|
+
return tenantId;
|
|
1721
|
+
};
|
|
1722
|
+
var models = {
|
|
1723
|
+
register: registerModels,
|
|
1724
|
+
getUnsafe: async (modelName, ctx) => {
|
|
1725
|
+
return loadModelFromDb(modelName, getTenantDbName(getTenantIdFromLoadModelCtx(ctx)), "tenant");
|
|
1726
|
+
},
|
|
1727
|
+
get: async (modelName, ctx) => {
|
|
1728
|
+
const model = await models.getUnsafe(modelName, ctx);
|
|
1729
|
+
const resolvedAbility = ctx.ability;
|
|
1730
|
+
if (!hasRegisteredPolicy(modelName)) return model;
|
|
1731
|
+
if (!resolvedAbility) throw new Error(`Model "${modelName}" is ACL-protected. Set ctx.ability or use models.getUnsafe(...) explicitly.`);
|
|
1732
|
+
if (typeof model.acl !== "function") return model;
|
|
1733
|
+
return model.acl(resolvedAbility);
|
|
1734
|
+
},
|
|
1735
|
+
getGlobal: async (modelName, ctx) => {
|
|
1736
|
+
return loadModelFromDb(modelName, getGlobalDbName(), "global");
|
|
1737
|
+
}
|
|
1738
|
+
};
|
|
1739
|
+
//#endregion
|
|
1740
|
+
//#region src/createModels.ts
|
|
1741
|
+
var createModels = (modules) => {
|
|
1742
|
+
registerModels(modules);
|
|
1743
|
+
const get = (async (modelNameOrNames, ctx) => {
|
|
1744
|
+
if (Array.isArray(modelNameOrNames)) return Promise.all(modelNameOrNames.map((modelName) => models.get(modelName, ctx)));
|
|
1745
|
+
return models.get(modelNameOrNames, ctx);
|
|
1746
|
+
});
|
|
1747
|
+
const getUnsafe = (async (modelNameOrNames, ctx) => {
|
|
1748
|
+
if (Array.isArray(modelNameOrNames)) return Promise.all(modelNameOrNames.map((modelName) => models.getUnsafe(modelName, ctx)));
|
|
1749
|
+
return models.getUnsafe(modelNameOrNames, ctx);
|
|
1750
|
+
});
|
|
1751
|
+
const getGlobal = (async (modelNameOrNames, ctx) => {
|
|
1752
|
+
if (Array.isArray(modelNameOrNames)) return Promise.all(modelNameOrNames.map((modelName) => models.getGlobal(modelName, ctx)));
|
|
1753
|
+
return models.getGlobal(modelNameOrNames, ctx);
|
|
1754
|
+
});
|
|
1755
|
+
return {
|
|
1756
|
+
register: registerModels,
|
|
1757
|
+
get,
|
|
1758
|
+
getUnsafe,
|
|
1759
|
+
getGlobal
|
|
1760
|
+
};
|
|
1761
|
+
};
|
|
1762
|
+
//#endregion
|
|
1763
|
+
//#region src/tenantFilesystemDb.ts
|
|
1764
|
+
var getAppName = () => {
|
|
1765
|
+
const appName = process.env.APP_NAME?.trim();
|
|
1766
|
+
assert(appName, "Missing APP_NAME");
|
|
1767
|
+
return appName;
|
|
1768
|
+
};
|
|
1769
|
+
var normalizeTenantId = (tenantId) => {
|
|
1770
|
+
const normalized = tenantId.trim();
|
|
1771
|
+
assert(normalized, "Tenant ID is missing");
|
|
1772
|
+
return normalized;
|
|
1773
|
+
};
|
|
1774
|
+
var getTenantFilesystemDbName = (tenantId) => `${getAppName()}-${normalizeTenantId(tenantId)}-filesystem-db`;
|
|
1775
|
+
var getTenantFilesystemDb = async (tenantId) => ensureMongooseConnection(getTenantFilesystemDbName(tenantId));
|
|
1776
|
+
var getTenantFilesystemDbFromCtx = async (ctx) => {
|
|
1777
|
+
return getTenantFilesystemDb(getTenantIdFromLoadModelCtx(ctx));
|
|
1778
|
+
};
|
|
1779
|
+
//#endregion
|
|
1780
|
+
//#region src/transactions.ts
|
|
1781
|
+
var buildTenantLoadModelCtx = (tenantId) => ({ req: { session: { user: { currentTenantId: tenantId } } } });
|
|
2000
1782
|
async function withTransaction(scope, fn, options) {
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
}), options);
|
|
2034
|
-
} finally {
|
|
2035
|
-
await session.endSession();
|
|
2036
|
-
}
|
|
1783
|
+
const normalizedTenantId = (() => {
|
|
1784
|
+
if (typeof scope === "string") return scope.trim();
|
|
1785
|
+
if ("tenantId" in scope) return scope.tenantId.trim();
|
|
1786
|
+
return getTenantIdFromLoadModelCtx(scope.ctx);
|
|
1787
|
+
})();
|
|
1788
|
+
if (!normalizedTenantId) throw new Error("Tenant ID is missing");
|
|
1789
|
+
const tenantDbName = getTenantDbName(normalizedTenantId);
|
|
1790
|
+
const globalDbName = getGlobalDbName();
|
|
1791
|
+
const filesystemDbName = getTenantFilesystemDbName(normalizedTenantId);
|
|
1792
|
+
const tenantDb = await ensureMongooseConnection(tenantDbName);
|
|
1793
|
+
const globalDb = await ensureMongooseConnection(globalDbName);
|
|
1794
|
+
const filesystemDb = await ensureMongooseConnection(filesystemDbName);
|
|
1795
|
+
const session = await tenantDb.startSession();
|
|
1796
|
+
const tenantCtx = typeof scope === "object" && "ctx" in scope ? scope.ctx : buildTenantLoadModelCtx(normalizedTenantId);
|
|
1797
|
+
const globalCtx = { req: { session: null } };
|
|
1798
|
+
try {
|
|
1799
|
+
return await session.withTransaction(async () => fn({
|
|
1800
|
+
tenantId: normalizedTenantId,
|
|
1801
|
+
session,
|
|
1802
|
+
ctx: {
|
|
1803
|
+
tenant: tenantCtx,
|
|
1804
|
+
global: globalCtx
|
|
1805
|
+
},
|
|
1806
|
+
db: {
|
|
1807
|
+
tenant: tenantDb,
|
|
1808
|
+
global: globalDb,
|
|
1809
|
+
filesystem: filesystemDb
|
|
1810
|
+
}
|
|
1811
|
+
}), options);
|
|
1812
|
+
} finally {
|
|
1813
|
+
await session.endSession();
|
|
1814
|
+
}
|
|
2037
1815
|
}
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
PaginationValidationError,
|
|
2043
|
-
RBNotificationPolicy,
|
|
2044
|
-
RBNotificationSchema,
|
|
2045
|
-
RBNotificationSettingsPolicy,
|
|
2046
|
-
RBNotificationSettingsSchema,
|
|
2047
|
-
RBOAuthRequestSchema,
|
|
2048
|
-
RBRtsChangeSchema,
|
|
2049
|
-
RBRtsCounterSchema,
|
|
2050
|
-
RBTenantSchema,
|
|
2051
|
-
RBTenantSubscriptionEventSchema,
|
|
2052
|
-
RBTenantSubscriptionSchema,
|
|
2053
|
-
RBUploadChunkSchema,
|
|
2054
|
-
RBUploadSessionPolicy,
|
|
2055
|
-
RBUploadSessionSchema,
|
|
2056
|
-
RBUserSchema,
|
|
2057
|
-
Schema,
|
|
2058
|
-
ZRBNotification,
|
|
2059
|
-
ZRBNotificationDigestFrequency,
|
|
2060
|
-
ZRBNotificationSettings,
|
|
2061
|
-
ZRBNotificationTopicPreference,
|
|
2062
|
-
ZRBOAuthRequest,
|
|
2063
|
-
ZRBRtsChange,
|
|
2064
|
-
ZRBRtsChangeOp,
|
|
2065
|
-
ZRBRtsCounter,
|
|
2066
|
-
ZRBTenant,
|
|
2067
|
-
ZRBTenantSubscription,
|
|
2068
|
-
ZRBTenantSubscriptionChangeDirection,
|
|
2069
|
-
ZRBTenantSubscriptionEvent,
|
|
2070
|
-
ZRBTenantSubscriptionEventSource,
|
|
2071
|
-
ZRBTenantSubscriptionIntervalUnit,
|
|
2072
|
-
ZRBTenantSubscriptionScope,
|
|
2073
|
-
ZRBTenantSubscriptionStatus,
|
|
2074
|
-
ZRBTenantSubscriptionType,
|
|
2075
|
-
ZRBUploadChunk,
|
|
2076
|
-
ZRBUploadSession,
|
|
2077
|
-
ZRBUploadSessionStatus,
|
|
2078
|
-
ZRBUser,
|
|
2079
|
-
b as buildAbility,
|
|
2080
|
-
d as buildAbilityFromSession,
|
|
2081
|
-
c2 as buildLocaleFallbackChain,
|
|
2082
|
-
buildSearchTextStage,
|
|
2083
|
-
f as can,
|
|
2084
|
-
createModels,
|
|
2085
|
-
ensureSearchIndex,
|
|
2086
|
-
extendMongooseSchema,
|
|
2087
|
-
e2 as extendZod,
|
|
2088
|
-
e as getAccessibleByQuery,
|
|
2089
|
-
g as getRegisteredPolicies,
|
|
2090
|
-
getTenantFilesystemDb,
|
|
2091
|
-
getTenantFilesystemDbFromCtx,
|
|
2092
|
-
getTenantFilesystemDbName,
|
|
2093
|
-
getTenantIdFromLoadModelCtx,
|
|
2094
|
-
c as getTenantRolesFromSessionUser,
|
|
2095
|
-
hasRegisteredPolicy,
|
|
2096
|
-
isPaginationValidationError,
|
|
2097
|
-
localizedStringField,
|
|
2098
|
-
m as makeZE164Phone,
|
|
2099
|
-
model,
|
|
2100
|
-
models,
|
|
2101
|
-
mongoPaginationPlugin,
|
|
2102
|
-
default2 as mongoose,
|
|
2103
|
-
omitMongooseSchemaPaths,
|
|
2104
|
-
registerPoliciesFromModules,
|
|
2105
|
-
r as registerPolicy,
|
|
2106
|
-
r2 as resolveLocalizedString,
|
|
2107
|
-
searchMetaProjection,
|
|
2108
|
-
withLocalizedStringFallback,
|
|
2109
|
-
withTransaction,
|
|
2110
|
-
z2 as z,
|
|
2111
|
-
b2 as zE164Phone,
|
|
2112
|
-
f2 as zI18nString,
|
|
2113
|
-
d2 as zLocalizedString
|
|
2114
|
-
};
|
|
2115
|
-
//# sourceMappingURL=index.js.map
|
|
1816
|
+
//#endregion
|
|
1817
|
+
export { E164_PHONE_OR_EMPTY_REGEX, E164_PHONE_REGEX, LANGUAGE_CODE_REGEX, PaginationValidationError, RBNotificationPolicy, RBNotificationSchema, RBNotificationSettingsPolicy, RBNotificationSettingsSchema, RBOAuthRequestSchema, RBRtsChangeSchema, RBRtsCounterSchema, RBTenantSchema, RBTenantSubscriptionEventSchema, RBTenantSubscriptionSchema, RBUploadChunkSchema, RBUploadSessionPolicy, RBUploadSessionSchema, RBUserSchema, Schema, ZRBNotification, ZRBNotificationDigestFrequency, ZRBNotificationSettings, ZRBNotificationTopicPreference, ZRBOAuthRequest, ZRBRtsChange, ZRBRtsChangeOp, ZRBRtsCounter, ZRBTenant, ZRBTenantSubscription, ZRBTenantSubscriptionChangeDirection, ZRBTenantSubscriptionEvent, ZRBTenantSubscriptionEventSource, ZRBTenantSubscriptionIntervalUnit, ZRBTenantSubscriptionScope, ZRBTenantSubscriptionStatus, ZRBTenantSubscriptionType, ZRBUploadChunk, ZRBUploadSession, ZRBUploadSessionStatus, ZRBUser, buildAbility, buildAbilityFromSession, buildLocaleFallbackChain, buildSearchTextStage, can, createModels, ensureSearchIndex, extendMongooseSchema, extendZod, getAccessibleByQuery, getRegisteredPolicies, getTenantFilesystemDb, getTenantFilesystemDbFromCtx, getTenantFilesystemDbName, getTenantIdFromLoadModelCtx, getTenantRolesFromSessionUser, hasRegisteredPolicy, isPaginationValidationError, localizedStringField, makeZE164Phone, model, models, mongoPaginationPlugin, mongoose, omitMongooseSchemaPaths, registerPoliciesFromModules, registerPolicy, resolveLocalizedString, searchMetaProjection, withLocalizedStringFallback, withTransaction, z, zE164Phone, zI18nString, zLocalizedString };
|
|
1818
|
+
|
|
1819
|
+
//# sourceMappingURL=index.js.map
|