@kikiutils/mongoose 1.2.1 → 1.3.1
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/constants.d.ts +168 -0
- package/package.json +8 -7
- package/types/index.d.ts +2 -1
- package/types/paginate.d.ts +9 -8
- package/utils.cjs +83 -0
- package/utils.d.ts +168 -0
- package/utils.mjs +82 -0
package/constants.d.ts
CHANGED
|
@@ -103,6 +103,174 @@ export declare const commonMongooseSchemas: {
|
|
|
103
103
|
};
|
|
104
104
|
};
|
|
105
105
|
readonly string: {
|
|
106
|
+
readonly ipv4: {
|
|
107
|
+
readonly nonRequired: {
|
|
108
|
+
readonly trim: true;
|
|
109
|
+
readonly type: StringConstructor;
|
|
110
|
+
readonly validate: {
|
|
111
|
+
readonly message: "`{VALUE}` is not a valid IPv4 address for path `{PATH}`.";
|
|
112
|
+
readonly validator: (value: string) => boolean;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
readonly private: {
|
|
116
|
+
readonly nonRequired: {
|
|
117
|
+
readonly private: true;
|
|
118
|
+
readonly trim: true;
|
|
119
|
+
readonly type: StringConstructor;
|
|
120
|
+
readonly validate: {
|
|
121
|
+
readonly message: "`{VALUE}` is not a valid IPv4 address for path `{PATH}`.";
|
|
122
|
+
readonly validator: (value: string) => boolean;
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
readonly required: {
|
|
126
|
+
readonly private: true;
|
|
127
|
+
readonly required: true;
|
|
128
|
+
readonly trim: true;
|
|
129
|
+
readonly type: StringConstructor;
|
|
130
|
+
readonly validate: {
|
|
131
|
+
readonly message: "`{VALUE}` is not a valid IPv4 address for path `{PATH}`.";
|
|
132
|
+
readonly validator: (value: string) => boolean;
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
readonly unique: {
|
|
136
|
+
readonly nonRequired: {
|
|
137
|
+
readonly private: true;
|
|
138
|
+
readonly unique: true;
|
|
139
|
+
readonly trim: true;
|
|
140
|
+
readonly type: StringConstructor;
|
|
141
|
+
readonly validate: {
|
|
142
|
+
readonly message: "`{VALUE}` is not a valid IPv4 address for path `{PATH}`.";
|
|
143
|
+
readonly validator: (value: string) => boolean;
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
readonly required: {
|
|
147
|
+
readonly private: true;
|
|
148
|
+
readonly required: true;
|
|
149
|
+
readonly unique: true;
|
|
150
|
+
readonly trim: true;
|
|
151
|
+
readonly type: StringConstructor;
|
|
152
|
+
readonly validate: {
|
|
153
|
+
readonly message: "`{VALUE}` is not a valid IPv4 address for path `{PATH}`.";
|
|
154
|
+
readonly validator: (value: string) => boolean;
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
readonly required: {
|
|
160
|
+
readonly required: true;
|
|
161
|
+
readonly trim: true;
|
|
162
|
+
readonly type: StringConstructor;
|
|
163
|
+
readonly validate: {
|
|
164
|
+
readonly message: "`{VALUE}` is not a valid IPv4 address for path `{PATH}`.";
|
|
165
|
+
readonly validator: (value: string) => boolean;
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
readonly unique: {
|
|
169
|
+
readonly nonRequired: {
|
|
170
|
+
readonly unique: true;
|
|
171
|
+
readonly trim: true;
|
|
172
|
+
readonly type: StringConstructor;
|
|
173
|
+
readonly validate: {
|
|
174
|
+
readonly message: "`{VALUE}` is not a valid IPv4 address for path `{PATH}`.";
|
|
175
|
+
readonly validator: (value: string) => boolean;
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
readonly required: {
|
|
179
|
+
readonly required: true;
|
|
180
|
+
readonly unique: true;
|
|
181
|
+
readonly trim: true;
|
|
182
|
+
readonly type: StringConstructor;
|
|
183
|
+
readonly validate: {
|
|
184
|
+
readonly message: "`{VALUE}` is not a valid IPv4 address for path `{PATH}`.";
|
|
185
|
+
readonly validator: (value: string) => boolean;
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
readonly ipv6: {
|
|
191
|
+
readonly nonRequired: {
|
|
192
|
+
readonly validate: {
|
|
193
|
+
readonly message: "`{VALUE}` is not a valid IPv6 address for path `{PATH}`.";
|
|
194
|
+
readonly validator: (value: string) => boolean;
|
|
195
|
+
};
|
|
196
|
+
readonly trim: true;
|
|
197
|
+
readonly type: StringConstructor;
|
|
198
|
+
};
|
|
199
|
+
readonly private: {
|
|
200
|
+
readonly nonRequired: {
|
|
201
|
+
readonly private: true;
|
|
202
|
+
readonly validate: {
|
|
203
|
+
readonly message: "`{VALUE}` is not a valid IPv6 address for path `{PATH}`.";
|
|
204
|
+
readonly validator: (value: string) => boolean;
|
|
205
|
+
};
|
|
206
|
+
readonly trim: true;
|
|
207
|
+
readonly type: StringConstructor;
|
|
208
|
+
};
|
|
209
|
+
readonly required: {
|
|
210
|
+
readonly private: true;
|
|
211
|
+
readonly required: true;
|
|
212
|
+
readonly validate: {
|
|
213
|
+
readonly message: "`{VALUE}` is not a valid IPv6 address for path `{PATH}`.";
|
|
214
|
+
readonly validator: (value: string) => boolean;
|
|
215
|
+
};
|
|
216
|
+
readonly trim: true;
|
|
217
|
+
readonly type: StringConstructor;
|
|
218
|
+
};
|
|
219
|
+
readonly unique: {
|
|
220
|
+
readonly nonRequired: {
|
|
221
|
+
readonly private: true;
|
|
222
|
+
readonly unique: true;
|
|
223
|
+
readonly validate: {
|
|
224
|
+
readonly message: "`{VALUE}` is not a valid IPv6 address for path `{PATH}`.";
|
|
225
|
+
readonly validator: (value: string) => boolean;
|
|
226
|
+
};
|
|
227
|
+
readonly trim: true;
|
|
228
|
+
readonly type: StringConstructor;
|
|
229
|
+
};
|
|
230
|
+
readonly required: {
|
|
231
|
+
readonly private: true;
|
|
232
|
+
readonly required: true;
|
|
233
|
+
readonly unique: true;
|
|
234
|
+
readonly validate: {
|
|
235
|
+
readonly message: "`{VALUE}` is not a valid IPv6 address for path `{PATH}`.";
|
|
236
|
+
readonly validator: (value: string) => boolean;
|
|
237
|
+
};
|
|
238
|
+
readonly trim: true;
|
|
239
|
+
readonly type: StringConstructor;
|
|
240
|
+
};
|
|
241
|
+
};
|
|
242
|
+
};
|
|
243
|
+
readonly required: {
|
|
244
|
+
readonly required: true;
|
|
245
|
+
readonly validate: {
|
|
246
|
+
readonly message: "`{VALUE}` is not a valid IPv6 address for path `{PATH}`.";
|
|
247
|
+
readonly validator: (value: string) => boolean;
|
|
248
|
+
};
|
|
249
|
+
readonly trim: true;
|
|
250
|
+
readonly type: StringConstructor;
|
|
251
|
+
};
|
|
252
|
+
readonly unique: {
|
|
253
|
+
readonly nonRequired: {
|
|
254
|
+
readonly unique: true;
|
|
255
|
+
readonly validate: {
|
|
256
|
+
readonly message: "`{VALUE}` is not a valid IPv6 address for path `{PATH}`.";
|
|
257
|
+
readonly validator: (value: string) => boolean;
|
|
258
|
+
};
|
|
259
|
+
readonly trim: true;
|
|
260
|
+
readonly type: StringConstructor;
|
|
261
|
+
};
|
|
262
|
+
readonly required: {
|
|
263
|
+
readonly required: true;
|
|
264
|
+
readonly unique: true;
|
|
265
|
+
readonly validate: {
|
|
266
|
+
readonly message: "`{VALUE}` is not a valid IPv6 address for path `{PATH}`.";
|
|
267
|
+
readonly validator: (value: string) => boolean;
|
|
268
|
+
};
|
|
269
|
+
readonly trim: true;
|
|
270
|
+
readonly type: StringConstructor;
|
|
271
|
+
};
|
|
272
|
+
};
|
|
273
|
+
};
|
|
106
274
|
readonly nonRequired: import("./types/schema").MongooseStringSchema<[]>;
|
|
107
275
|
readonly private: {
|
|
108
276
|
readonly nonRequired: import("./types/schema").MongooseStringSchema<["private"]>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kikiutils/mongoose",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "A Mongoose plugin for enhanced JSON normalization and common schema creation, with built-in support for pagination and automatic Decimal128 conversion.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "kiki-kanri",
|
|
@@ -15,17 +15,18 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"decimal.js": "^10.4.3",
|
|
17
17
|
"lodash": "^4.17.21",
|
|
18
|
-
"mongoose": "^8.
|
|
18
|
+
"mongoose": "^8.7.0",
|
|
19
19
|
"mongoose-aggregate-paginate-v2": "^1.1.2",
|
|
20
|
-
"mongoose-paginate-v2": "^1.8.
|
|
20
|
+
"mongoose-paginate-v2": "^1.8.5"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@kikiutils/prettierrc": "^1.3.2",
|
|
24
24
|
"@kikiutils/tsconfigs": "^3.0.1",
|
|
25
|
-
"@types/lodash": "^4.17.
|
|
26
|
-
"@types/node": "^22.
|
|
27
|
-
"changelogen": "^0.5.
|
|
28
|
-
"ts-project-builder": "^3.0.1"
|
|
25
|
+
"@types/lodash": "^4.17.9",
|
|
26
|
+
"@types/node": "^22.7.4",
|
|
27
|
+
"changelogen": "^0.5.7",
|
|
28
|
+
"ts-project-builder": "^3.0.1",
|
|
29
|
+
"tslib": "^2.7.0"
|
|
29
30
|
},
|
|
30
31
|
"keywords": [
|
|
31
32
|
"Decimal128",
|
package/types/index.d.ts
CHANGED
|
@@ -56,8 +56,9 @@ declare global {
|
|
|
56
56
|
* @template RawDocType - The raw document type as stored in MongoDB.
|
|
57
57
|
* @template DocType - The Mongoose document type after applying schema transformations.
|
|
58
58
|
* @template QueryHelpers - Optional type parameter for additional query helper methods.
|
|
59
|
+
* @template InstanceMethodsAndOverrides - Optional type parameter for specifying custom instance methods and overrides on the document.
|
|
59
60
|
*/
|
|
60
|
-
type MongooseFindOneReturnType<RawDocType, DocType, QueryHelpers = {}> = QueryWithHelpers<DocType | null, DocType, QueryHelpers, RawDocType, 'findOne'>;
|
|
61
|
+
type MongooseFindOneReturnType<RawDocType, DocType, QueryHelpers = {}, InstanceMethodsAndOverrides = {}> = QueryWithHelpers<DocType | null, DocType, QueryHelpers, RawDocType, 'findOne', InstanceMethodsAndOverrides>;
|
|
61
62
|
/**
|
|
62
63
|
* Type definition for a hydrated Mongoose document.
|
|
63
64
|
*
|
package/types/paginate.d.ts
CHANGED
|
@@ -64,17 +64,18 @@ declare module 'mongoose' {
|
|
|
64
64
|
meta?: any;
|
|
65
65
|
[customLabel: string]: T[] | number | boolean | null | undefined;
|
|
66
66
|
}
|
|
67
|
-
type PaginateDocument<T, TMethods,
|
|
67
|
+
type PaginateDocument<T, TMethods, TQueryHelpers, O extends PaginateOptions = {}> = O['lean'] extends true ? (O['leanWithId'] extends true ? T & {
|
|
68
68
|
id: string;
|
|
69
|
-
} : T) : HydratedDocument<T, TMethods,
|
|
69
|
+
} : T) : HydratedDocument<T, TMethods, TQueryHelpers>;
|
|
70
70
|
interface PaginateModel<T, TQueryHelpers = {}, TMethods = {}> extends Model<T, TQueryHelpers, TMethods> {
|
|
71
|
-
paginate<O extends PaginateOptions>(query?: FilterQuery<T>, options?: O, callback?: (err: any, result: PaginateResult<PaginateDocument<T, TMethods, O>>) => void): Promise<PaginateResult<PaginateDocument<T, TMethods, O>>>;
|
|
71
|
+
paginate<O extends PaginateOptions>(query?: FilterQuery<T>, options?: O, callback?: (err: any, result: PaginateResult<PaginateDocument<T, TMethods, TQueryHelpers, O>>) => void): Promise<PaginateResult<PaginateDocument<T, TMethods, TQueryHelpers, O>>>;
|
|
72
|
+
paginate<UserType = T, O extends PaginateOptions = PaginateOptions>(query?: FilterQuery<T>, options?: O, callback?: (err: any, result: PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, O>>) => void): Promise<PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, O>>>;
|
|
73
|
+
paginate<UserType = T>(query?: FilterQuery<T>, options?: PaginateOptions, callback?: (err: any, result: PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, PaginateOptions>>) => void): Promise<PaginateResult<PaginateDocument<UserType, TMethods, TQueryHelpers, PaginateOptions>>>;
|
|
72
74
|
}
|
|
73
|
-
interface
|
|
74
|
-
paginate<
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
paginate<UserType = T>(query?: FilterQuery<T>, options?: PaginateOptions, callback?: (err: any, result: PaginateResult<PaginateDocument<UserType, TMethods, PaginateOptions>>) => void): Promise<PaginateResult<PaginateDocument<UserType, TMethods, PaginateOptions>>>;
|
|
75
|
+
interface Query<ResultType, DocType, THelpers = NonNullable<unknown>, RawDocType = DocType, QueryOp = 'find', TInstanceMethods = Record<string, never>> {
|
|
76
|
+
paginate<O extends PaginateOptions>(options?: O): Promise<PaginateResult<PaginateDocument<RawDocType, TInstanceMethods, THelpers, O>>>;
|
|
77
|
+
paginate<UserType = ResultType, O extends PaginateOptions = PaginateOptions>(options?: O): Promise<PaginateResult<PaginateDocument<UserType, TInstanceMethods, THelpers, O>>>;
|
|
78
|
+
paginate<UserType = ResultType>(options?: PaginateOptions): Promise<PaginateResult<PaginateDocument<UserType, TInstanceMethods, THelpers, PaginateOptions>>>;
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
declare function _(schema: Schema): void;
|
package/utils.cjs
CHANGED
|
@@ -5,6 +5,7 @@ const lodash = require('lodash');
|
|
|
5
5
|
const mongoose = require('mongoose');
|
|
6
6
|
const mongooseAggregatePaginate = require('mongoose-aggregate-paginate-v2');
|
|
7
7
|
const mongoosePaginate = require('mongoose-paginate-v2');
|
|
8
|
+
const net = require('node:net');
|
|
8
9
|
const _connections = require('./_connections.cjs');
|
|
9
10
|
const normalize = require('./plugins/normalize.cjs');
|
|
10
11
|
|
|
@@ -15,6 +16,7 @@ const lodash__default = /*#__PURE__*/_interopDefaultCompat(lodash);
|
|
|
15
16
|
const mongoose__default = /*#__PURE__*/_interopDefaultCompat(mongoose);
|
|
16
17
|
const mongooseAggregatePaginate__default = /*#__PURE__*/_interopDefaultCompat(mongooseAggregatePaginate);
|
|
17
18
|
const mongoosePaginate__default = /*#__PURE__*/_interopDefaultCompat(mongoosePaginate);
|
|
19
|
+
const net__default = /*#__PURE__*/_interopDefaultCompat(net);
|
|
18
20
|
|
|
19
21
|
const { merge } = lodash__default;
|
|
20
22
|
/**
|
|
@@ -70,6 +72,21 @@ function createCommonMongooseSchemas(customSchemas, options) {
|
|
|
70
72
|
set: (value) => new Decimal__default(value.toString()).toFixed(autoRoundAndToFixedDecimal128Places, autoRoundAndToFixedDecimal128Rounding),
|
|
71
73
|
type: mongoose__default.Schema.Types.Decimal128
|
|
72
74
|
};
|
|
75
|
+
const baseIPv4 = {
|
|
76
|
+
trim: true,
|
|
77
|
+
type: String,
|
|
78
|
+
validate: {
|
|
79
|
+
message: '`{VALUE}` is not a valid IPv4 address for path `{PATH}`.',
|
|
80
|
+
validator: (value) => net__default.isIPv4(value)
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const baseIPv6 = {
|
|
84
|
+
...baseIPv4,
|
|
85
|
+
validate: {
|
|
86
|
+
message: '`{VALUE}` is not a valid IPv6 address for path `{PATH}`.',
|
|
87
|
+
validator: (value) => net__default.isIPv6(value)
|
|
88
|
+
}
|
|
89
|
+
};
|
|
73
90
|
const baseRequiredBoolean = { required: true, type: Boolean };
|
|
74
91
|
const baseRequiredNumber = { required: true, type: Number };
|
|
75
92
|
const baseRequiredObjectId = { required: true, type: mongoose__default.Schema.Types.ObjectId };
|
|
@@ -111,6 +128,72 @@ function createCommonMongooseSchemas(customSchemas, options) {
|
|
|
111
128
|
}
|
|
112
129
|
},
|
|
113
130
|
string: {
|
|
131
|
+
ipv4: {
|
|
132
|
+
nonRequired: baseIPv4,
|
|
133
|
+
private: {
|
|
134
|
+
nonRequired: { ...baseIPv4, private: true },
|
|
135
|
+
required: {
|
|
136
|
+
...baseIPv4,
|
|
137
|
+
private: true,
|
|
138
|
+
required: true
|
|
139
|
+
},
|
|
140
|
+
unique: {
|
|
141
|
+
nonRequired: {
|
|
142
|
+
...baseIPv4,
|
|
143
|
+
private: true,
|
|
144
|
+
unique: true
|
|
145
|
+
},
|
|
146
|
+
required: {
|
|
147
|
+
...baseIPv4,
|
|
148
|
+
private: true,
|
|
149
|
+
required: true,
|
|
150
|
+
unique: true
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
required: { ...baseIPv4, required: true },
|
|
155
|
+
unique: {
|
|
156
|
+
nonRequired: { ...baseIPv4, unique: true },
|
|
157
|
+
required: {
|
|
158
|
+
...baseIPv4,
|
|
159
|
+
required: true,
|
|
160
|
+
unique: true
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
ipv6: {
|
|
165
|
+
nonRequired: baseIPv6,
|
|
166
|
+
private: {
|
|
167
|
+
nonRequired: { ...baseIPv6, private: true },
|
|
168
|
+
required: {
|
|
169
|
+
...baseIPv6,
|
|
170
|
+
private: true,
|
|
171
|
+
required: true
|
|
172
|
+
},
|
|
173
|
+
unique: {
|
|
174
|
+
nonRequired: {
|
|
175
|
+
...baseIPv6,
|
|
176
|
+
private: true,
|
|
177
|
+
unique: true
|
|
178
|
+
},
|
|
179
|
+
required: {
|
|
180
|
+
...baseIPv6,
|
|
181
|
+
private: true,
|
|
182
|
+
required: true,
|
|
183
|
+
unique: true
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
required: { ...baseIPv6, required: true },
|
|
188
|
+
unique: {
|
|
189
|
+
nonRequired: { ...baseIPv6, unique: true },
|
|
190
|
+
required: {
|
|
191
|
+
...baseIPv6,
|
|
192
|
+
required: true,
|
|
193
|
+
unique: true
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
},
|
|
114
197
|
nonRequired: createMongooseStringSchema(),
|
|
115
198
|
private: {
|
|
116
199
|
nonRequired: createMongooseStringSchema('private'),
|
package/utils.d.ts
CHANGED
|
@@ -137,6 +137,174 @@ export declare function createCommonMongooseSchemas<T extends {}>(customSchemas?
|
|
|
137
137
|
};
|
|
138
138
|
};
|
|
139
139
|
readonly string: {
|
|
140
|
+
readonly ipv4: {
|
|
141
|
+
readonly nonRequired: {
|
|
142
|
+
readonly trim: true;
|
|
143
|
+
readonly type: StringConstructor;
|
|
144
|
+
readonly validate: {
|
|
145
|
+
readonly message: "`{VALUE}` is not a valid IPv4 address for path `{PATH}`.";
|
|
146
|
+
readonly validator: (value: string) => boolean;
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
readonly private: {
|
|
150
|
+
readonly nonRequired: {
|
|
151
|
+
readonly private: true;
|
|
152
|
+
readonly trim: true;
|
|
153
|
+
readonly type: StringConstructor;
|
|
154
|
+
readonly validate: {
|
|
155
|
+
readonly message: "`{VALUE}` is not a valid IPv4 address for path `{PATH}`.";
|
|
156
|
+
readonly validator: (value: string) => boolean;
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
readonly required: {
|
|
160
|
+
readonly private: true;
|
|
161
|
+
readonly required: true;
|
|
162
|
+
readonly trim: true;
|
|
163
|
+
readonly type: StringConstructor;
|
|
164
|
+
readonly validate: {
|
|
165
|
+
readonly message: "`{VALUE}` is not a valid IPv4 address for path `{PATH}`.";
|
|
166
|
+
readonly validator: (value: string) => boolean;
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
readonly unique: {
|
|
170
|
+
readonly nonRequired: {
|
|
171
|
+
readonly private: true;
|
|
172
|
+
readonly unique: true;
|
|
173
|
+
readonly trim: true;
|
|
174
|
+
readonly type: StringConstructor;
|
|
175
|
+
readonly validate: {
|
|
176
|
+
readonly message: "`{VALUE}` is not a valid IPv4 address for path `{PATH}`.";
|
|
177
|
+
readonly validator: (value: string) => boolean;
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
readonly required: {
|
|
181
|
+
readonly private: true;
|
|
182
|
+
readonly required: true;
|
|
183
|
+
readonly unique: true;
|
|
184
|
+
readonly trim: true;
|
|
185
|
+
readonly type: StringConstructor;
|
|
186
|
+
readonly validate: {
|
|
187
|
+
readonly message: "`{VALUE}` is not a valid IPv4 address for path `{PATH}`.";
|
|
188
|
+
readonly validator: (value: string) => boolean;
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
readonly required: {
|
|
194
|
+
readonly required: true;
|
|
195
|
+
readonly trim: true;
|
|
196
|
+
readonly type: StringConstructor;
|
|
197
|
+
readonly validate: {
|
|
198
|
+
readonly message: "`{VALUE}` is not a valid IPv4 address for path `{PATH}`.";
|
|
199
|
+
readonly validator: (value: string) => boolean;
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
readonly unique: {
|
|
203
|
+
readonly nonRequired: {
|
|
204
|
+
readonly unique: true;
|
|
205
|
+
readonly trim: true;
|
|
206
|
+
readonly type: StringConstructor;
|
|
207
|
+
readonly validate: {
|
|
208
|
+
readonly message: "`{VALUE}` is not a valid IPv4 address for path `{PATH}`.";
|
|
209
|
+
readonly validator: (value: string) => boolean;
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
readonly required: {
|
|
213
|
+
readonly required: true;
|
|
214
|
+
readonly unique: true;
|
|
215
|
+
readonly trim: true;
|
|
216
|
+
readonly type: StringConstructor;
|
|
217
|
+
readonly validate: {
|
|
218
|
+
readonly message: "`{VALUE}` is not a valid IPv4 address for path `{PATH}`.";
|
|
219
|
+
readonly validator: (value: string) => boolean;
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
readonly ipv6: {
|
|
225
|
+
readonly nonRequired: {
|
|
226
|
+
readonly validate: {
|
|
227
|
+
readonly message: "`{VALUE}` is not a valid IPv6 address for path `{PATH}`.";
|
|
228
|
+
readonly validator: (value: string) => boolean;
|
|
229
|
+
};
|
|
230
|
+
readonly trim: true;
|
|
231
|
+
readonly type: StringConstructor;
|
|
232
|
+
};
|
|
233
|
+
readonly private: {
|
|
234
|
+
readonly nonRequired: {
|
|
235
|
+
readonly private: true;
|
|
236
|
+
readonly validate: {
|
|
237
|
+
readonly message: "`{VALUE}` is not a valid IPv6 address for path `{PATH}`.";
|
|
238
|
+
readonly validator: (value: string) => boolean;
|
|
239
|
+
};
|
|
240
|
+
readonly trim: true;
|
|
241
|
+
readonly type: StringConstructor;
|
|
242
|
+
};
|
|
243
|
+
readonly required: {
|
|
244
|
+
readonly private: true;
|
|
245
|
+
readonly required: true;
|
|
246
|
+
readonly validate: {
|
|
247
|
+
readonly message: "`{VALUE}` is not a valid IPv6 address for path `{PATH}`.";
|
|
248
|
+
readonly validator: (value: string) => boolean;
|
|
249
|
+
};
|
|
250
|
+
readonly trim: true;
|
|
251
|
+
readonly type: StringConstructor;
|
|
252
|
+
};
|
|
253
|
+
readonly unique: {
|
|
254
|
+
readonly nonRequired: {
|
|
255
|
+
readonly private: true;
|
|
256
|
+
readonly unique: true;
|
|
257
|
+
readonly validate: {
|
|
258
|
+
readonly message: "`{VALUE}` is not a valid IPv6 address for path `{PATH}`.";
|
|
259
|
+
readonly validator: (value: string) => boolean;
|
|
260
|
+
};
|
|
261
|
+
readonly trim: true;
|
|
262
|
+
readonly type: StringConstructor;
|
|
263
|
+
};
|
|
264
|
+
readonly required: {
|
|
265
|
+
readonly private: true;
|
|
266
|
+
readonly required: true;
|
|
267
|
+
readonly unique: true;
|
|
268
|
+
readonly validate: {
|
|
269
|
+
readonly message: "`{VALUE}` is not a valid IPv6 address for path `{PATH}`.";
|
|
270
|
+
readonly validator: (value: string) => boolean;
|
|
271
|
+
};
|
|
272
|
+
readonly trim: true;
|
|
273
|
+
readonly type: StringConstructor;
|
|
274
|
+
};
|
|
275
|
+
};
|
|
276
|
+
};
|
|
277
|
+
readonly required: {
|
|
278
|
+
readonly required: true;
|
|
279
|
+
readonly validate: {
|
|
280
|
+
readonly message: "`{VALUE}` is not a valid IPv6 address for path `{PATH}`.";
|
|
281
|
+
readonly validator: (value: string) => boolean;
|
|
282
|
+
};
|
|
283
|
+
readonly trim: true;
|
|
284
|
+
readonly type: StringConstructor;
|
|
285
|
+
};
|
|
286
|
+
readonly unique: {
|
|
287
|
+
readonly nonRequired: {
|
|
288
|
+
readonly unique: true;
|
|
289
|
+
readonly validate: {
|
|
290
|
+
readonly message: "`{VALUE}` is not a valid IPv6 address for path `{PATH}`.";
|
|
291
|
+
readonly validator: (value: string) => boolean;
|
|
292
|
+
};
|
|
293
|
+
readonly trim: true;
|
|
294
|
+
readonly type: StringConstructor;
|
|
295
|
+
};
|
|
296
|
+
readonly required: {
|
|
297
|
+
readonly required: true;
|
|
298
|
+
readonly unique: true;
|
|
299
|
+
readonly validate: {
|
|
300
|
+
readonly message: "`{VALUE}` is not a valid IPv6 address for path `{PATH}`.";
|
|
301
|
+
readonly validator: (value: string) => boolean;
|
|
302
|
+
};
|
|
303
|
+
readonly trim: true;
|
|
304
|
+
readonly type: StringConstructor;
|
|
305
|
+
};
|
|
306
|
+
};
|
|
307
|
+
};
|
|
140
308
|
readonly nonRequired: MongooseStringSchema<[]>;
|
|
141
309
|
readonly private: {
|
|
142
310
|
readonly nonRequired: MongooseStringSchema<["private"]>;
|
package/utils.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import lodash from 'lodash';
|
|
|
3
3
|
import mongoose, { Types } from 'mongoose';
|
|
4
4
|
import mongooseAggregatePaginate from 'mongoose-aggregate-paginate-v2';
|
|
5
5
|
import mongoosePaginate from 'mongoose-paginate-v2';
|
|
6
|
+
import net from 'node:net';
|
|
6
7
|
import { mongooseConnections } from './_connections.mjs';
|
|
7
8
|
import { mongooseNormalizePlugin } from './plugins/normalize.mjs';
|
|
8
9
|
|
|
@@ -60,6 +61,21 @@ function createCommonMongooseSchemas(customSchemas, options) {
|
|
|
60
61
|
set: (value) => new Decimal(value.toString()).toFixed(autoRoundAndToFixedDecimal128Places, autoRoundAndToFixedDecimal128Rounding),
|
|
61
62
|
type: mongoose.Schema.Types.Decimal128
|
|
62
63
|
};
|
|
64
|
+
const baseIPv4 = {
|
|
65
|
+
trim: true,
|
|
66
|
+
type: String,
|
|
67
|
+
validate: {
|
|
68
|
+
message: '`{VALUE}` is not a valid IPv4 address for path `{PATH}`.',
|
|
69
|
+
validator: (value) => net.isIPv4(value)
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const baseIPv6 = {
|
|
73
|
+
...baseIPv4,
|
|
74
|
+
validate: {
|
|
75
|
+
message: '`{VALUE}` is not a valid IPv6 address for path `{PATH}`.',
|
|
76
|
+
validator: (value) => net.isIPv6(value)
|
|
77
|
+
}
|
|
78
|
+
};
|
|
63
79
|
const baseRequiredBoolean = { required: true, type: Boolean };
|
|
64
80
|
const baseRequiredNumber = { required: true, type: Number };
|
|
65
81
|
const baseRequiredObjectId = { required: true, type: mongoose.Schema.Types.ObjectId };
|
|
@@ -101,6 +117,72 @@ function createCommonMongooseSchemas(customSchemas, options) {
|
|
|
101
117
|
}
|
|
102
118
|
},
|
|
103
119
|
string: {
|
|
120
|
+
ipv4: {
|
|
121
|
+
nonRequired: baseIPv4,
|
|
122
|
+
private: {
|
|
123
|
+
nonRequired: { ...baseIPv4, private: true },
|
|
124
|
+
required: {
|
|
125
|
+
...baseIPv4,
|
|
126
|
+
private: true,
|
|
127
|
+
required: true
|
|
128
|
+
},
|
|
129
|
+
unique: {
|
|
130
|
+
nonRequired: {
|
|
131
|
+
...baseIPv4,
|
|
132
|
+
private: true,
|
|
133
|
+
unique: true
|
|
134
|
+
},
|
|
135
|
+
required: {
|
|
136
|
+
...baseIPv4,
|
|
137
|
+
private: true,
|
|
138
|
+
required: true,
|
|
139
|
+
unique: true
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
required: { ...baseIPv4, required: true },
|
|
144
|
+
unique: {
|
|
145
|
+
nonRequired: { ...baseIPv4, unique: true },
|
|
146
|
+
required: {
|
|
147
|
+
...baseIPv4,
|
|
148
|
+
required: true,
|
|
149
|
+
unique: true
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
ipv6: {
|
|
154
|
+
nonRequired: baseIPv6,
|
|
155
|
+
private: {
|
|
156
|
+
nonRequired: { ...baseIPv6, private: true },
|
|
157
|
+
required: {
|
|
158
|
+
...baseIPv6,
|
|
159
|
+
private: true,
|
|
160
|
+
required: true
|
|
161
|
+
},
|
|
162
|
+
unique: {
|
|
163
|
+
nonRequired: {
|
|
164
|
+
...baseIPv6,
|
|
165
|
+
private: true,
|
|
166
|
+
unique: true
|
|
167
|
+
},
|
|
168
|
+
required: {
|
|
169
|
+
...baseIPv6,
|
|
170
|
+
private: true,
|
|
171
|
+
required: true,
|
|
172
|
+
unique: true
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
required: { ...baseIPv6, required: true },
|
|
177
|
+
unique: {
|
|
178
|
+
nonRequired: { ...baseIPv6, unique: true },
|
|
179
|
+
required: {
|
|
180
|
+
...baseIPv6,
|
|
181
|
+
required: true,
|
|
182
|
+
unique: true
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
},
|
|
104
186
|
nonRequired: createMongooseStringSchema(),
|
|
105
187
|
private: {
|
|
106
188
|
nonRequired: createMongooseStringSchema('private'),
|