express-model-binding 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/{BaseAdapter-BjvLQijd.d.mts → BaseAdapter-Dr9a8ZUY.d.mts} +17 -1
  2. package/dist/{BaseAdapter-BjvLQijd.d.ts → BaseAdapter-Dr9a8ZUY.d.ts} +17 -1
  3. package/dist/adapters/KnexAdapter.d.mts +1 -1
  4. package/dist/adapters/KnexAdapter.d.ts +1 -1
  5. package/dist/adapters/KnexAdapter.js +1 -257
  6. package/dist/adapters/KnexAdapter.mjs +1 -229
  7. package/dist/adapters/MongooseAdapter.d.mts +1 -1
  8. package/dist/adapters/MongooseAdapter.d.ts +1 -1
  9. package/dist/adapters/MongooseAdapter.js +1 -245
  10. package/dist/adapters/MongooseAdapter.mjs +1 -225
  11. package/dist/adapters/PrismaAdapter.d.mts +1 -1
  12. package/dist/adapters/PrismaAdapter.d.ts +1 -1
  13. package/dist/adapters/PrismaAdapter.js +1 -247
  14. package/dist/adapters/PrismaAdapter.mjs +1 -220
  15. package/dist/adapters/SequelizeAdapter.d.mts +1 -1
  16. package/dist/adapters/SequelizeAdapter.d.ts +1 -1
  17. package/dist/adapters/SequelizeAdapter.js +1 -280
  18. package/dist/adapters/SequelizeAdapter.mjs +1 -260
  19. package/dist/adapters/TypeORMAdapter.d.mts +1 -1
  20. package/dist/adapters/TypeORMAdapter.d.ts +1 -1
  21. package/dist/adapters/TypeORMAdapter.js +1 -294
  22. package/dist/adapters/TypeORMAdapter.mjs +1 -267
  23. package/dist/chunk-7I3EYD6K.js +1 -0
  24. package/dist/chunk-7OR75DD2.mjs +1 -0
  25. package/dist/chunk-A7LUHNSI.mjs +1 -0
  26. package/dist/chunk-B3DBSP2J.mjs +1 -0
  27. package/dist/chunk-CKT6LD2K.js +1 -0
  28. package/dist/chunk-DBYMXDVA.mjs +1 -0
  29. package/dist/chunk-EEPSARTF.js +1 -0
  30. package/dist/chunk-ISSVD3WP.js +1 -0
  31. package/dist/chunk-LLYCNTZ7.mjs +1 -0
  32. package/dist/chunk-OKPAWWZN.js +1 -0
  33. package/dist/chunk-Z6WU7X3A.mjs +1 -0
  34. package/dist/chunk-ZJ2WW53U.js +1 -0
  35. package/dist/index.d.mts +4 -3
  36. package/dist/index.d.ts +4 -3
  37. package/dist/index.js +1 -1514
  38. package/dist/index.mjs +1 -1450
  39. package/package.json +5 -3
  40. package/dist/adapters/KnexAdapter.js.map +0 -1
  41. package/dist/adapters/KnexAdapter.mjs.map +0 -1
  42. package/dist/adapters/MongooseAdapter.js.map +0 -1
  43. package/dist/adapters/MongooseAdapter.mjs.map +0 -1
  44. package/dist/adapters/PrismaAdapter.js.map +0 -1
  45. package/dist/adapters/PrismaAdapter.mjs.map +0 -1
  46. package/dist/adapters/SequelizeAdapter.js.map +0 -1
  47. package/dist/adapters/SequelizeAdapter.mjs.map +0 -1
  48. package/dist/adapters/TypeORMAdapter.js.map +0 -1
  49. package/dist/adapters/TypeORMAdapter.mjs.map +0 -1
  50. package/dist/index.js.map +0 -1
  51. package/dist/index.mjs.map +0 -1
@@ -1,280 +1 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/adapters/SequelizeAdapter.ts
21
- var SequelizeAdapter_exports = {};
22
- __export(SequelizeAdapter_exports, {
23
- SequelizeAdapter: () => SequelizeAdapter
24
- });
25
- module.exports = __toCommonJS(SequelizeAdapter_exports);
26
-
27
- // src/errors/index.ts
28
- var BindingError = class extends Error {
29
- constructor(message, originalError) {
30
- super(message);
31
- this.name = "BindingError";
32
- this.originalError = originalError;
33
- Error.captureStackTrace(this, this.constructor);
34
- }
35
- toJSON() {
36
- return {
37
- name: this.name,
38
- message: this.message,
39
- originalError: this.originalError?.message
40
- };
41
- }
42
- };
43
- var InvalidModelError = class extends Error {
44
- constructor(message, model) {
45
- super(message);
46
- this.name = "InvalidModelError";
47
- this.model = model;
48
- Error.captureStackTrace(this, this.constructor);
49
- }
50
- toJSON() {
51
- return {
52
- name: this.name,
53
- message: this.message,
54
- model: typeof this.model === "string" ? this.model : String(this.model)
55
- };
56
- }
57
- };
58
-
59
- // src/core/BaseAdapter.ts
60
- var BaseAdapter = class {
61
- transformValue(_model, _key, value) {
62
- if (/^\d+$/.test(value)) {
63
- const num = parseInt(value, 10);
64
- if (!isNaN(num) && Number.isSafeInteger(num)) {
65
- return num;
66
- }
67
- }
68
- return value;
69
- }
70
- supportsSoftDeletes(_model) {
71
- return false;
72
- }
73
- getModelMetadata(model) {
74
- return {
75
- name: this.getModelName(model),
76
- primaryKey: this.getPrimaryKeyName(model),
77
- softDeletes: this.supportsSoftDeletes(model),
78
- adapter: this.name
79
- };
80
- }
81
- validateModel(model) {
82
- if (!this.isValidModel(model)) {
83
- throw new InvalidModelError(`Invalid model for ${this.name} adapter`, model);
84
- }
85
- }
86
- getModelName(model) {
87
- if (typeof model === "string") {
88
- return model;
89
- }
90
- if (model && typeof model === "object") {
91
- const obj = model;
92
- if (typeof obj.name === "string") return obj.name;
93
- if (typeof obj.modelName === "string") return obj.modelName;
94
- if (typeof obj.tableName === "string") return obj.tableName;
95
- }
96
- if (model && typeof model === "function") {
97
- return model.name || "Unknown";
98
- }
99
- return "Unknown";
100
- }
101
- applySoftDeleteFilter(queryBuilder, _options) {
102
- return queryBuilder;
103
- }
104
- applyIncludes(queryBuilder, _includes) {
105
- return queryBuilder;
106
- }
107
- applySelect(queryBuilder, _select) {
108
- return queryBuilder;
109
- }
110
- applyWhereConditions(queryBuilder, _where) {
111
- return queryBuilder;
112
- }
113
- applyCustomQuery(queryBuilder, queryFn) {
114
- if (queryFn) {
115
- return queryFn(queryBuilder);
116
- }
117
- return queryBuilder;
118
- }
119
- };
120
-
121
- // src/utils/validators.ts
122
- var UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
123
- function isUUID(value) {
124
- return UUID_REGEX.test(value);
125
- }
126
-
127
- // src/adapters/SequelizeAdapter.ts
128
- function isSequelizeModel(model) {
129
- if (!model || typeof model !== "function") {
130
- return false;
131
- }
132
- const m = model;
133
- return typeof m.findOne === "function" && typeof m.findAll === "function" && typeof m.rawAttributes === "object";
134
- }
135
- var SequelizeAdapter = class extends BaseAdapter {
136
- constructor(sequelize) {
137
- super();
138
- this.sequelize = sequelize;
139
- this.name = "sequelize";
140
- }
141
- getSequelize() {
142
- return this.sequelize;
143
- }
144
- async findByKey(model, key, value, options = {}) {
145
- this.validateModel(model);
146
- try {
147
- const transformedValue = this.transformValue(model, key, value);
148
- const findOptions = {
149
- where: { [key]: transformedValue }
150
- };
151
- if (options.select && options.select.length > 0) {
152
- findOptions.attributes = options.select;
153
- }
154
- if (options.include) {
155
- findOptions.include = this.buildIncludes(options.include);
156
- }
157
- if (options.where) {
158
- findOptions.where = {
159
- ...findOptions.where,
160
- ...options.where
161
- };
162
- }
163
- const isParanoid = model.options?.paranoid;
164
- if (isParanoid) {
165
- if (options.withTrashed) {
166
- findOptions.paranoid = false;
167
- } else if (options.onlyTrashed) {
168
- findOptions.paranoid = false;
169
- const { Op: SeqOp } = require("sequelize");
170
- const whereClause = findOptions.where;
171
- whereClause.deletedAt = { [SeqOp.ne]: null };
172
- }
173
- }
174
- if (options.lock === "forUpdate") {
175
- findOptions.lock = true;
176
- } else if (options.lock === "forShare") {
177
- const { Transaction: SeqTransaction } = require("sequelize");
178
- findOptions.lock = SeqTransaction.LOCK.SHARE;
179
- }
180
- let result = await model.findOne(findOptions);
181
- if (options.query && !result) {
182
- result = await this.findWithCustomQuery(model, key, transformedValue, options);
183
- }
184
- return result;
185
- } catch (error) {
186
- throw new BindingError(
187
- `Failed to fetch ${model.name}: ${error.message}`,
188
- error
189
- );
190
- }
191
- }
192
- getPrimaryKeyName(model) {
193
- return model.primaryKeyAttribute || "id";
194
- }
195
- isValidModel(model) {
196
- return isSequelizeModel(model);
197
- }
198
- transformValue(model, key, value) {
199
- const attributes = model.rawAttributes;
200
- const attribute = attributes?.[key];
201
- if (!attribute) {
202
- if (isUUID(value)) {
203
- return value;
204
- }
205
- const num = parseInt(value, 10);
206
- if (!isNaN(num) && num.toString() === value) {
207
- return num;
208
- }
209
- return value;
210
- }
211
- const attrType = attribute.type;
212
- const type = attrType?.constructor?.name || String(attrType);
213
- switch (type) {
214
- case "INTEGER":
215
- case "BIGINT":
216
- case "SMALLINT": {
217
- const intNum = parseInt(value, 10);
218
- return isNaN(intNum) ? value : intNum;
219
- }
220
- case "FLOAT":
221
- case "DOUBLE":
222
- case "DECIMAL": {
223
- const floatNum = parseFloat(value);
224
- return isNaN(floatNum) ? value : floatNum;
225
- }
226
- case "BOOLEAN":
227
- return value === "true" || value === "1";
228
- case "UUID":
229
- return value;
230
- default:
231
- return value;
232
- }
233
- }
234
- supportsSoftDeletes(model) {
235
- return !!model.options?.paranoid;
236
- }
237
- getModelMetadata(model) {
238
- const tableName = model.tableName || model.name;
239
- const associations = Object.keys(model.associations || {});
240
- return {
241
- name: model.name,
242
- primaryKey: this.getPrimaryKeyName(model),
243
- tableName,
244
- softDeletes: this.supportsSoftDeletes(model),
245
- relations: associations,
246
- adapter: this.name
247
- };
248
- }
249
- buildIncludes(includes) {
250
- if (Array.isArray(includes)) {
251
- return includes.map((relation) => ({ association: relation }));
252
- }
253
- return Object.entries(includes).map(([relation, opts]) => {
254
- if (typeof opts === "boolean" && opts) {
255
- return { association: relation };
256
- }
257
- if (typeof opts === "object" && opts !== null) {
258
- return {
259
- association: relation,
260
- ...opts
261
- };
262
- }
263
- return { association: relation };
264
- });
265
- }
266
- async findWithCustomQuery(model, key, value, options) {
267
- const findOptions = {
268
- where: { [key]: value }
269
- };
270
- if (options.query) {
271
- options.query(findOptions);
272
- }
273
- return await model.findOne(findOptions);
274
- }
275
- };
276
- // Annotate the CommonJS export names for ESM import in node:
277
- 0 && (module.exports = {
278
- SequelizeAdapter
279
- });
280
- //# sourceMappingURL=SequelizeAdapter.js.map
1
+ 'use strict';var chunkISSVD3WP_js=require('../chunk-ISSVD3WP.js');require('../chunk-7I3EYD6K.js');Object.defineProperty(exports,"SequelizeAdapter",{enumerable:true,get:function(){return chunkISSVD3WP_js.a}});
@@ -1,260 +1 @@
1
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined") return require.apply(this, arguments);
5
- throw Error('Dynamic require of "' + x + '" is not supported');
6
- });
7
-
8
- // src/errors/index.ts
9
- var BindingError = class extends Error {
10
- constructor(message, originalError) {
11
- super(message);
12
- this.name = "BindingError";
13
- this.originalError = originalError;
14
- Error.captureStackTrace(this, this.constructor);
15
- }
16
- toJSON() {
17
- return {
18
- name: this.name,
19
- message: this.message,
20
- originalError: this.originalError?.message
21
- };
22
- }
23
- };
24
- var InvalidModelError = class extends Error {
25
- constructor(message, model) {
26
- super(message);
27
- this.name = "InvalidModelError";
28
- this.model = model;
29
- Error.captureStackTrace(this, this.constructor);
30
- }
31
- toJSON() {
32
- return {
33
- name: this.name,
34
- message: this.message,
35
- model: typeof this.model === "string" ? this.model : String(this.model)
36
- };
37
- }
38
- };
39
-
40
- // src/core/BaseAdapter.ts
41
- var BaseAdapter = class {
42
- transformValue(_model, _key, value) {
43
- if (/^\d+$/.test(value)) {
44
- const num = parseInt(value, 10);
45
- if (!isNaN(num) && Number.isSafeInteger(num)) {
46
- return num;
47
- }
48
- }
49
- return value;
50
- }
51
- supportsSoftDeletes(_model) {
52
- return false;
53
- }
54
- getModelMetadata(model) {
55
- return {
56
- name: this.getModelName(model),
57
- primaryKey: this.getPrimaryKeyName(model),
58
- softDeletes: this.supportsSoftDeletes(model),
59
- adapter: this.name
60
- };
61
- }
62
- validateModel(model) {
63
- if (!this.isValidModel(model)) {
64
- throw new InvalidModelError(`Invalid model for ${this.name} adapter`, model);
65
- }
66
- }
67
- getModelName(model) {
68
- if (typeof model === "string") {
69
- return model;
70
- }
71
- if (model && typeof model === "object") {
72
- const obj = model;
73
- if (typeof obj.name === "string") return obj.name;
74
- if (typeof obj.modelName === "string") return obj.modelName;
75
- if (typeof obj.tableName === "string") return obj.tableName;
76
- }
77
- if (model && typeof model === "function") {
78
- return model.name || "Unknown";
79
- }
80
- return "Unknown";
81
- }
82
- applySoftDeleteFilter(queryBuilder, _options) {
83
- return queryBuilder;
84
- }
85
- applyIncludes(queryBuilder, _includes) {
86
- return queryBuilder;
87
- }
88
- applySelect(queryBuilder, _select) {
89
- return queryBuilder;
90
- }
91
- applyWhereConditions(queryBuilder, _where) {
92
- return queryBuilder;
93
- }
94
- applyCustomQuery(queryBuilder, queryFn) {
95
- if (queryFn) {
96
- return queryFn(queryBuilder);
97
- }
98
- return queryBuilder;
99
- }
100
- };
101
-
102
- // src/utils/validators.ts
103
- var UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
104
- function isUUID(value) {
105
- return UUID_REGEX.test(value);
106
- }
107
-
108
- // src/adapters/SequelizeAdapter.ts
109
- function isSequelizeModel(model) {
110
- if (!model || typeof model !== "function") {
111
- return false;
112
- }
113
- const m = model;
114
- return typeof m.findOne === "function" && typeof m.findAll === "function" && typeof m.rawAttributes === "object";
115
- }
116
- var SequelizeAdapter = class extends BaseAdapter {
117
- constructor(sequelize) {
118
- super();
119
- this.sequelize = sequelize;
120
- this.name = "sequelize";
121
- }
122
- getSequelize() {
123
- return this.sequelize;
124
- }
125
- async findByKey(model, key, value, options = {}) {
126
- this.validateModel(model);
127
- try {
128
- const transformedValue = this.transformValue(model, key, value);
129
- const findOptions = {
130
- where: { [key]: transformedValue }
131
- };
132
- if (options.select && options.select.length > 0) {
133
- findOptions.attributes = options.select;
134
- }
135
- if (options.include) {
136
- findOptions.include = this.buildIncludes(options.include);
137
- }
138
- if (options.where) {
139
- findOptions.where = {
140
- ...findOptions.where,
141
- ...options.where
142
- };
143
- }
144
- const isParanoid = model.options?.paranoid;
145
- if (isParanoid) {
146
- if (options.withTrashed) {
147
- findOptions.paranoid = false;
148
- } else if (options.onlyTrashed) {
149
- findOptions.paranoid = false;
150
- const { Op: SeqOp } = __require("sequelize");
151
- const whereClause = findOptions.where;
152
- whereClause.deletedAt = { [SeqOp.ne]: null };
153
- }
154
- }
155
- if (options.lock === "forUpdate") {
156
- findOptions.lock = true;
157
- } else if (options.lock === "forShare") {
158
- const { Transaction: SeqTransaction } = __require("sequelize");
159
- findOptions.lock = SeqTransaction.LOCK.SHARE;
160
- }
161
- let result = await model.findOne(findOptions);
162
- if (options.query && !result) {
163
- result = await this.findWithCustomQuery(model, key, transformedValue, options);
164
- }
165
- return result;
166
- } catch (error) {
167
- throw new BindingError(
168
- `Failed to fetch ${model.name}: ${error.message}`,
169
- error
170
- );
171
- }
172
- }
173
- getPrimaryKeyName(model) {
174
- return model.primaryKeyAttribute || "id";
175
- }
176
- isValidModel(model) {
177
- return isSequelizeModel(model);
178
- }
179
- transformValue(model, key, value) {
180
- const attributes = model.rawAttributes;
181
- const attribute = attributes?.[key];
182
- if (!attribute) {
183
- if (isUUID(value)) {
184
- return value;
185
- }
186
- const num = parseInt(value, 10);
187
- if (!isNaN(num) && num.toString() === value) {
188
- return num;
189
- }
190
- return value;
191
- }
192
- const attrType = attribute.type;
193
- const type = attrType?.constructor?.name || String(attrType);
194
- switch (type) {
195
- case "INTEGER":
196
- case "BIGINT":
197
- case "SMALLINT": {
198
- const intNum = parseInt(value, 10);
199
- return isNaN(intNum) ? value : intNum;
200
- }
201
- case "FLOAT":
202
- case "DOUBLE":
203
- case "DECIMAL": {
204
- const floatNum = parseFloat(value);
205
- return isNaN(floatNum) ? value : floatNum;
206
- }
207
- case "BOOLEAN":
208
- return value === "true" || value === "1";
209
- case "UUID":
210
- return value;
211
- default:
212
- return value;
213
- }
214
- }
215
- supportsSoftDeletes(model) {
216
- return !!model.options?.paranoid;
217
- }
218
- getModelMetadata(model) {
219
- const tableName = model.tableName || model.name;
220
- const associations = Object.keys(model.associations || {});
221
- return {
222
- name: model.name,
223
- primaryKey: this.getPrimaryKeyName(model),
224
- tableName,
225
- softDeletes: this.supportsSoftDeletes(model),
226
- relations: associations,
227
- adapter: this.name
228
- };
229
- }
230
- buildIncludes(includes) {
231
- if (Array.isArray(includes)) {
232
- return includes.map((relation) => ({ association: relation }));
233
- }
234
- return Object.entries(includes).map(([relation, opts]) => {
235
- if (typeof opts === "boolean" && opts) {
236
- return { association: relation };
237
- }
238
- if (typeof opts === "object" && opts !== null) {
239
- return {
240
- association: relation,
241
- ...opts
242
- };
243
- }
244
- return { association: relation };
245
- });
246
- }
247
- async findWithCustomQuery(model, key, value, options) {
248
- const findOptions = {
249
- where: { [key]: value }
250
- };
251
- if (options.query) {
252
- options.query(findOptions);
253
- }
254
- return await model.findOne(findOptions);
255
- }
256
- };
257
- export {
258
- SequelizeAdapter
259
- };
260
- //# sourceMappingURL=SequelizeAdapter.mjs.map
1
+ export{a as SequelizeAdapter}from'../chunk-7OR75DD2.mjs';import'../chunk-DBYMXDVA.mjs';
@@ -1,5 +1,5 @@
1
1
  import { EntityTarget, ObjectLiteral, SelectQueryBuilder, DataSource } from 'typeorm';
2
- import { b as BaseAdapter, Q as QueryOptions, d as ModelMetadata } from '../BaseAdapter-BjvLQijd.mjs';
2
+ import { b as BaseAdapter, Q as QueryOptions, d as ModelMetadata } from '../BaseAdapter-Dr9a8ZUY.mjs';
3
3
  import 'express';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  import { EntityTarget, ObjectLiteral, SelectQueryBuilder, DataSource } from 'typeorm';
2
- import { b as BaseAdapter, Q as QueryOptions, d as ModelMetadata } from '../BaseAdapter-BjvLQijd.js';
2
+ import { b as BaseAdapter, Q as QueryOptions, d as ModelMetadata } from '../BaseAdapter-Dr9a8ZUY.js';
3
3
  import 'express';
4
4
 
5
5
  /**