@zenstackhq/runtime 2.16.0 → 3.0.0-alpha.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 (236) hide show
  1. package/LICENSE +1 -1
  2. package/dist/client.cjs +6094 -0
  3. package/dist/client.cjs.map +1 -0
  4. package/dist/client.d.cts +19 -0
  5. package/dist/client.d.ts +19 -0
  6. package/dist/client.js +6060 -0
  7. package/dist/client.js.map +1 -0
  8. package/dist/contract-DguafRNB.d.cts +1272 -0
  9. package/dist/contract-DguafRNB.d.ts +1272 -0
  10. package/dist/index.cjs +6088 -0
  11. package/dist/index.cjs.map +1 -0
  12. package/dist/index.d.cts +14 -0
  13. package/dist/index.d.ts +14 -0
  14. package/dist/index.js +6057 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/plugins/policy.cjs +2343 -0
  17. package/dist/plugins/policy.cjs.map +1 -0
  18. package/dist/plugins/policy.d.cts +24 -0
  19. package/dist/plugins/policy.d.ts +24 -0
  20. package/dist/plugins/policy.js +2307 -0
  21. package/dist/plugins/policy.js.map +1 -0
  22. package/dist/schema.cjs +110 -0
  23. package/dist/schema.cjs.map +1 -0
  24. package/dist/schema.d.cts +29 -0
  25. package/dist/schema.d.ts +29 -0
  26. package/dist/schema.js +85 -0
  27. package/dist/schema.js.map +1 -0
  28. package/dist/utils/pg-utils.cjs +39 -0
  29. package/dist/utils/pg-utils.cjs.map +1 -0
  30. package/dist/utils/pg-utils.d.cts +8 -0
  31. package/dist/utils/pg-utils.d.ts +8 -0
  32. package/dist/utils/pg-utils.js +16 -0
  33. package/dist/utils/pg-utils.js.map +1 -0
  34. package/{browser/index.js → dist/utils/sqlite-utils.cjs} +21 -37
  35. package/dist/utils/sqlite-utils.cjs.map +1 -0
  36. package/dist/utils/sqlite-utils.d.cts +8 -0
  37. package/dist/utils/sqlite-utils.d.ts +8 -0
  38. package/dist/utils/sqlite-utils.js +22 -0
  39. package/dist/utils/sqlite-utils.js.map +1 -0
  40. package/package.json +106 -117
  41. package/README.md +0 -5
  42. package/browser/index.d.mts +0 -13
  43. package/browser/index.d.ts +0 -13
  44. package/browser/index.js.map +0 -1
  45. package/browser/index.mjs +0 -33
  46. package/browser/index.mjs.map +0 -1
  47. package/constants.d.ts +0 -62
  48. package/constants.js +0 -76
  49. package/constants.js.map +0 -1
  50. package/cross/index.d.mts +0 -379
  51. package/cross/index.d.ts +0 -379
  52. package/cross/index.js +0 -923
  53. package/cross/index.js.map +0 -1
  54. package/cross/index.mjs +0 -881
  55. package/cross/index.mjs.map +0 -1
  56. package/edge.d.ts +0 -1
  57. package/edge.js +0 -18
  58. package/edge.js.map +0 -1
  59. package/encryption/index.d.ts +0 -25
  60. package/encryption/index.js +0 -74
  61. package/encryption/index.js.map +0 -1
  62. package/encryption/utils.d.ts +0 -9
  63. package/encryption/utils.js +0 -99
  64. package/encryption/utils.js.map +0 -1
  65. package/enhance-edge.d.ts +0 -1
  66. package/enhance-edge.js +0 -10
  67. package/enhance.d.ts +0 -1
  68. package/enhance.js +0 -10
  69. package/enhancements/edge/create-enhancement.d.ts +0 -42
  70. package/enhancements/edge/create-enhancement.js +0 -102
  71. package/enhancements/edge/create-enhancement.js.map +0 -1
  72. package/enhancements/edge/default-auth.d.ts +0 -8
  73. package/enhancements/edge/default-auth.js +0 -180
  74. package/enhancements/edge/default-auth.js.map +0 -1
  75. package/enhancements/edge/delegate.d.ts +0 -77
  76. package/enhancements/edge/delegate.js +0 -1293
  77. package/enhancements/edge/delegate.js.map +0 -1
  78. package/enhancements/edge/encryption.d.ts +0 -7
  79. package/enhancements/edge/encryption.js +0 -150
  80. package/enhancements/edge/encryption.js.map +0 -1
  81. package/enhancements/edge/index.d.ts +0 -4
  82. package/enhancements/edge/index.js +0 -21
  83. package/enhancements/edge/index.js.map +0 -1
  84. package/enhancements/edge/json-processor.d.ts +0 -7
  85. package/enhancements/edge/json-processor.js +0 -89
  86. package/enhancements/edge/json-processor.js.map +0 -1
  87. package/enhancements/edge/logger.d.ts +0 -29
  88. package/enhancements/edge/logger.js +0 -65
  89. package/enhancements/edge/logger.js.map +0 -1
  90. package/enhancements/edge/omit.d.ts +0 -7
  91. package/enhancements/edge/omit.js +0 -96
  92. package/enhancements/edge/omit.js.map +0 -1
  93. package/enhancements/edge/password.d.ts +0 -7
  94. package/enhancements/edge/password.js +0 -64
  95. package/enhancements/edge/password.js.map +0 -1
  96. package/enhancements/edge/policy/check-utils.d.ts +0 -5
  97. package/enhancements/edge/policy/check-utils.js +0 -20
  98. package/enhancements/edge/policy/check-utils.js.map +0 -1
  99. package/enhancements/edge/policy/handler.d.ts +0 -100
  100. package/enhancements/edge/policy/handler.js +0 -1440
  101. package/enhancements/edge/policy/handler.js.map +0 -1
  102. package/enhancements/edge/policy/index.d.ts +0 -19
  103. package/enhancements/edge/policy/index.js +0 -65
  104. package/enhancements/edge/policy/index.js.map +0 -1
  105. package/enhancements/edge/policy/policy-utils.d.ts +0 -181
  106. package/enhancements/edge/policy/policy-utils.js +0 -1356
  107. package/enhancements/edge/policy/policy-utils.js.map +0 -1
  108. package/enhancements/edge/promise.d.ts +0 -15
  109. package/enhancements/edge/promise.js +0 -99
  110. package/enhancements/edge/promise.js.map +0 -1
  111. package/enhancements/edge/proxy.d.ts +0 -120
  112. package/enhancements/edge/proxy.js +0 -287
  113. package/enhancements/edge/proxy.js.map +0 -1
  114. package/enhancements/edge/query-utils.d.ts +0 -53
  115. package/enhancements/edge/query-utils.js +0 -256
  116. package/enhancements/edge/query-utils.js.map +0 -1
  117. package/enhancements/edge/types.d.ts +0 -238
  118. package/enhancements/edge/types.js +0 -3
  119. package/enhancements/edge/types.js.map +0 -1
  120. package/enhancements/edge/utils.d.ts +0 -11
  121. package/enhancements/edge/utils.js +0 -49
  122. package/enhancements/edge/utils.js.map +0 -1
  123. package/enhancements/edge/where-visitor.d.ts +0 -32
  124. package/enhancements/edge/where-visitor.js +0 -86
  125. package/enhancements/edge/where-visitor.js.map +0 -1
  126. package/enhancements/node/create-enhancement.d.ts +0 -42
  127. package/enhancements/node/create-enhancement.js +0 -102
  128. package/enhancements/node/create-enhancement.js.map +0 -1
  129. package/enhancements/node/default-auth.d.ts +0 -8
  130. package/enhancements/node/default-auth.js +0 -180
  131. package/enhancements/node/default-auth.js.map +0 -1
  132. package/enhancements/node/delegate.d.ts +0 -77
  133. package/enhancements/node/delegate.js +0 -1293
  134. package/enhancements/node/delegate.js.map +0 -1
  135. package/enhancements/node/encryption.d.ts +0 -7
  136. package/enhancements/node/encryption.js +0 -150
  137. package/enhancements/node/encryption.js.map +0 -1
  138. package/enhancements/node/index.d.ts +0 -4
  139. package/enhancements/node/index.js +0 -21
  140. package/enhancements/node/index.js.map +0 -1
  141. package/enhancements/node/json-processor.d.ts +0 -7
  142. package/enhancements/node/json-processor.js +0 -89
  143. package/enhancements/node/json-processor.js.map +0 -1
  144. package/enhancements/node/logger.d.ts +0 -29
  145. package/enhancements/node/logger.js +0 -65
  146. package/enhancements/node/logger.js.map +0 -1
  147. package/enhancements/node/omit.d.ts +0 -7
  148. package/enhancements/node/omit.js +0 -96
  149. package/enhancements/node/omit.js.map +0 -1
  150. package/enhancements/node/password.d.ts +0 -7
  151. package/enhancements/node/password.js +0 -64
  152. package/enhancements/node/password.js.map +0 -1
  153. package/enhancements/node/policy/check-utils.d.ts +0 -5
  154. package/enhancements/node/policy/check-utils.js +0 -87
  155. package/enhancements/node/policy/check-utils.js.map +0 -1
  156. package/enhancements/node/policy/constraint-solver.d.ts +0 -27
  157. package/enhancements/node/policy/constraint-solver.js +0 -164
  158. package/enhancements/node/policy/constraint-solver.js.map +0 -1
  159. package/enhancements/node/policy/handler.d.ts +0 -100
  160. package/enhancements/node/policy/handler.js +0 -1440
  161. package/enhancements/node/policy/handler.js.map +0 -1
  162. package/enhancements/node/policy/index.d.ts +0 -19
  163. package/enhancements/node/policy/index.js +0 -65
  164. package/enhancements/node/policy/index.js.map +0 -1
  165. package/enhancements/node/policy/policy-utils.d.ts +0 -181
  166. package/enhancements/node/policy/policy-utils.js +0 -1356
  167. package/enhancements/node/policy/policy-utils.js.map +0 -1
  168. package/enhancements/node/promise.d.ts +0 -15
  169. package/enhancements/node/promise.js +0 -99
  170. package/enhancements/node/promise.js.map +0 -1
  171. package/enhancements/node/proxy.d.ts +0 -120
  172. package/enhancements/node/proxy.js +0 -287
  173. package/enhancements/node/proxy.js.map +0 -1
  174. package/enhancements/node/query-utils.d.ts +0 -53
  175. package/enhancements/node/query-utils.js +0 -256
  176. package/enhancements/node/query-utils.js.map +0 -1
  177. package/enhancements/node/types.d.ts +0 -238
  178. package/enhancements/node/types.js +0 -3
  179. package/enhancements/node/types.js.map +0 -1
  180. package/enhancements/node/utils.d.ts +0 -11
  181. package/enhancements/node/utils.js +0 -49
  182. package/enhancements/node/utils.js.map +0 -1
  183. package/enhancements/node/where-visitor.d.ts +0 -32
  184. package/enhancements/node/where-visitor.js +0 -86
  185. package/enhancements/node/where-visitor.js.map +0 -1
  186. package/error.d.ts +0 -11
  187. package/error.js +0 -22
  188. package/error.js.map +0 -1
  189. package/index.d.ts +0 -7
  190. package/index.js +0 -24
  191. package/index.js.map +0 -1
  192. package/local-helpers/index.d.ts +0 -6
  193. package/local-helpers/index.js +0 -23
  194. package/local-helpers/index.js.map +0 -1
  195. package/local-helpers/is-plain-object.d.ts +0 -1
  196. package/local-helpers/is-plain-object.js +0 -25
  197. package/local-helpers/is-plain-object.js.map +0 -1
  198. package/local-helpers/lower-case-first.d.ts +0 -1
  199. package/local-helpers/lower-case-first.js +0 -7
  200. package/local-helpers/lower-case-first.js.map +0 -1
  201. package/local-helpers/param-case.d.ts +0 -1
  202. package/local-helpers/param-case.js +0 -20
  203. package/local-helpers/param-case.js.map +0 -1
  204. package/local-helpers/sleep.d.ts +0 -1
  205. package/local-helpers/sleep.js +0 -9
  206. package/local-helpers/sleep.js.map +0 -1
  207. package/local-helpers/tiny-invariant.d.ts +0 -1
  208. package/local-helpers/tiny-invariant.js +0 -15
  209. package/local-helpers/tiny-invariant.js.map +0 -1
  210. package/local-helpers/upper-case-first.d.ts +0 -1
  211. package/local-helpers/upper-case-first.js +0 -7
  212. package/local-helpers/upper-case-first.js.map +0 -1
  213. package/model-meta.d.ts +0 -1
  214. package/model-meta.js +0 -10
  215. package/models.d.ts +0 -1
  216. package/models.js +0 -1
  217. package/types.d.ts +0 -200
  218. package/types.js +0 -4
  219. package/types.js.map +0 -1
  220. package/validation.d.ts +0 -24
  221. package/validation.js +0 -52
  222. package/validation.js.map +0 -1
  223. package/version.d.ts +0 -5
  224. package/version.js +0 -35
  225. package/version.js.map +0 -1
  226. package/zod/index.d.ts +0 -3
  227. package/zod/index.js +0 -5
  228. package/zod/input.d.ts +0 -1
  229. package/zod/input.js +0 -8
  230. package/zod/models.d.ts +0 -1
  231. package/zod/models.js +0 -8
  232. package/zod/objects.d.ts +0 -1
  233. package/zod/objects.js +0 -8
  234. package/zod-utils.d.ts +0 -12
  235. package/zod-utils.js +0 -97
  236. package/zod-utils.js.map +0 -1
@@ -1,86 +0,0 @@
1
- "use strict";
2
- /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
3
- /* eslint-disable @typescript-eslint/no-explicit-any */
4
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
5
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6
- return new (P || (P = Promise))(function (resolve, reject) {
7
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
8
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
9
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
10
- step((generator = generator.apply(thisArg, _arguments || [])).next());
11
- });
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.WhereVisitor = void 0;
15
- const cross_1 = require("../../cross");
16
- const FILTER_OPERATORS = [
17
- 'equals',
18
- 'not',
19
- 'in',
20
- 'notIn',
21
- 'lt',
22
- 'lte',
23
- 'gt',
24
- 'gte',
25
- 'contains',
26
- 'search',
27
- 'startsWith',
28
- 'endsWith',
29
- ];
30
- const RELATION_FILTER_OPERATORS = ['is', 'isNot', 'some', 'every', 'none'];
31
- /**
32
- * Recursive visitor for where payload
33
- */
34
- class WhereVisitor {
35
- constructor(modelMeta, callback) {
36
- this.modelMeta = modelMeta;
37
- this.callback = callback;
38
- }
39
- /**
40
- * Start visiting
41
- */
42
- visit(model, where) {
43
- return __awaiter(this, void 0, void 0, function* () {
44
- var _a, _b, _c, _d;
45
- if (!where) {
46
- return;
47
- }
48
- for (const [k, v] of Object.entries(where)) {
49
- if (['AND', 'OR', 'NOT'].includes(k)) {
50
- for (const item of (0, cross_1.enumerate)(v)) {
51
- yield this.visit(model, item);
52
- }
53
- continue;
54
- }
55
- if (RELATION_FILTER_OPERATORS.includes(k)) {
56
- // visit into filter body
57
- yield this.visit(model, v);
58
- continue;
59
- }
60
- const field = (0, cross_1.resolveField)(this.modelMeta, model, k);
61
- if (!field) {
62
- continue;
63
- }
64
- if (typeof v === 'object') {
65
- const filterOp = Object.keys(v).find((f) => FILTER_OPERATORS.includes(f));
66
- if (filterOp) {
67
- // reach into filter value
68
- const newValue = yield ((_b = (_a = this.callback).field) === null || _b === void 0 ? void 0 : _b.call(_a, field, v[filterOp]));
69
- v[filterOp] = newValue;
70
- continue;
71
- }
72
- if (Object.keys(v).some((f) => RELATION_FILTER_OPERATORS.includes(f))) {
73
- // filter payload
74
- yield this.visit(field.type, v);
75
- continue;
76
- }
77
- }
78
- // scalar field
79
- const newValue = yield ((_d = (_c = this.callback).field) === null || _d === void 0 ? void 0 : _d.call(_c, field, v));
80
- where[k] = newValue;
81
- }
82
- });
83
- }
84
- }
85
- exports.WhereVisitor = WhereVisitor;
86
- //# sourceMappingURL=where-visitor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"where-visitor.js","sourceRoot":"","sources":["../../../src/enhancements/node/where-visitor.ts"],"names":[],"mappings":";AAAA,sEAAsE;AACtE,uDAAuD;;;;;;;;;;;;AAEvD,uCAAsF;AAwBtF,MAAM,gBAAgB,GAAG;IACrB,QAAQ;IACR,KAAK;IACL,IAAI;IACJ,OAAO;IACP,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,KAAK;IACL,UAAU;IACV,QAAQ;IACR,YAAY;IACZ,UAAU;CACb,CAAC;AAEF,MAAM,yBAAyB,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AAE3E;;GAEG;AACH,MAAa,YAAY;IACrB,YAA6B,SAAoB,EAAmB,QAA8B;QAArE,cAAS,GAAT,SAAS,CAAW;QAAmB,aAAQ,GAAR,QAAQ,CAAsB;IAAG,CAAC;IAEtG;;OAEG;IACG,KAAK,CAAC,KAAa,EAAE,KAAU;;;YACjC,IAAI,CAAC,KAAK,EAAE,CAAC;gBACT,OAAO;YACX,CAAC;YAED,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAM,KAAK,CAAC,EAAE,CAAC;gBAC9C,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;oBACnC,KAAK,MAAM,IAAI,IAAI,IAAA,iBAAS,EAAC,CAAC,CAAC,EAAE,CAAC;wBAC9B,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;oBAClC,CAAC;oBACD,SAAS;gBACb,CAAC;gBAED,IAAI,yBAAyB,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;oBACxC,yBAAyB;oBACzB,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;oBAC3B,SAAS;gBACb,CAAC;gBAED,MAAM,KAAK,GAAG,IAAA,oBAAY,EAAC,IAAI,CAAC,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;gBACrD,IAAI,CAAC,KAAK,EAAE,CAAC;oBACT,SAAS;gBACb,CAAC;gBAED,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;oBACxB,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;oBAC1E,IAAI,QAAQ,EAAE,CAAC;wBACX,0BAA0B;wBAC1B,MAAM,QAAQ,GAAG,MAAM,CAAA,MAAA,MAAA,IAAI,CAAC,QAAQ,EAAC,KAAK,mDAAG,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAA,CAAC;wBACjE,CAAC,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;wBACvB,SAAS;oBACb,CAAC;oBAED,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,yBAAyB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;wBACpE,iBAAiB;wBACjB,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;wBAChC,SAAS;oBACb,CAAC;gBACL,CAAC;gBAED,eAAe;gBACf,MAAM,QAAQ,GAAG,MAAM,CAAA,MAAA,MAAA,IAAI,CAAC,QAAQ,EAAC,KAAK,mDAAG,KAAK,EAAE,CAAC,CAAC,CAAA,CAAC;gBACvD,KAAK,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC;YACxB,CAAC;QACL,CAAC;KAAA;CACJ;AAnDD,oCAmDC"}
package/error.d.ts DELETED
@@ -1,11 +0,0 @@
1
- export declare function isPrismaClientKnownRequestError(err: any): err is {
2
- code: string;
3
- message: string;
4
- meta?: Record<string, unknown>;
5
- };
6
- export declare function isPrismaClientUnknownRequestError(err: any): err is {
7
- message: string;
8
- };
9
- export declare function isPrismaClientValidationError(err: any): err is {
10
- message: string;
11
- };
package/error.js DELETED
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isPrismaClientKnownRequestError = isPrismaClientKnownRequestError;
4
- exports.isPrismaClientUnknownRequestError = isPrismaClientUnknownRequestError;
5
- exports.isPrismaClientValidationError = isPrismaClientValidationError;
6
- /* eslint-disable @typescript-eslint/no-explicit-any */
7
- function isPrismaClientKnownRequestError(err) {
8
- return findConstructorName(err.__proto__, 'PrismaClientKnownRequestError');
9
- }
10
- function isPrismaClientUnknownRequestError(err) {
11
- return findConstructorName(err.__proto__, 'PrismaClientUnknownRequestError');
12
- }
13
- function isPrismaClientValidationError(err) {
14
- return findConstructorName(err.__proto__, 'PrismaClientValidationError');
15
- }
16
- function findConstructorName(proto, name) {
17
- if (!proto) {
18
- return false;
19
- }
20
- return proto.constructor.name === name || findConstructorName(proto.__proto__, name);
21
- }
22
- //# sourceMappingURL=error.js.map
package/error.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":";;AACA,0EAIC;AAED,8EAEC;AAED,sEAEC;AAbD,uDAAuD;AACvD,SAAgB,+BAA+B,CAC3C,GAAQ;IAER,OAAO,mBAAmB,CAAC,GAAG,CAAC,SAAS,EAAE,+BAA+B,CAAC,CAAC;AAC/E,CAAC;AAED,SAAgB,iCAAiC,CAAC,GAAQ;IACtD,OAAO,mBAAmB,CAAC,GAAG,CAAC,SAAS,EAAE,iCAAiC,CAAC,CAAC;AACjF,CAAC;AAED,SAAgB,6BAA6B,CAAC,GAAQ;IAClD,OAAO,mBAAmB,CAAC,GAAG,CAAC,SAAS,EAAE,6BAA6B,CAAC,CAAC;AAC7E,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAU,EAAE,IAAY;IACjD,IAAI,CAAC,KAAK,EAAE,CAAC;QACT,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,OAAO,KAAK,CAAC,WAAW,CAAC,IAAI,KAAK,IAAI,IAAI,mBAAmB,CAAC,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AACzF,CAAC"}
package/index.d.ts DELETED
@@ -1,7 +0,0 @@
1
- export * from './constants';
2
- export * from './cross';
3
- export * from './enhance';
4
- export * from './error';
5
- export * from './types';
6
- export * from './validation';
7
- export * from './version';
package/index.js DELETED
@@ -1,24 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./constants"), exports);
18
- __exportStar(require("./cross"), exports);
19
- __exportStar(require("./enhance"), exports);
20
- __exportStar(require("./error"), exports);
21
- __exportStar(require("./types"), exports);
22
- __exportStar(require("./validation"), exports);
23
- __exportStar(require("./version"), exports);
24
- //# sourceMappingURL=index.js.map
package/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,0CAAwB;AACxB,4CAA0B;AAC1B,0CAAwB;AACxB,0CAAwB;AACxB,+CAA6B;AAC7B,4CAA0B"}
@@ -1,6 +0,0 @@
1
- export * from './sleep';
2
- export * from './is-plain-object';
3
- export * from './lower-case-first';
4
- export * from './upper-case-first';
5
- export * from './param-case';
6
- export * from './tiny-invariant';
@@ -1,23 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./sleep"), exports);
18
- __exportStar(require("./is-plain-object"), exports);
19
- __exportStar(require("./lower-case-first"), exports);
20
- __exportStar(require("./upper-case-first"), exports);
21
- __exportStar(require("./param-case"), exports);
22
- __exportStar(require("./tiny-invariant"), exports);
23
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/local-helpers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,oDAAkC;AAClC,qDAAmC;AACnC,qDAAmC;AACnC,+CAA6B;AAC7B,mDAAiC"}
@@ -1 +0,0 @@
1
- export declare function isPlainObject(o: unknown): boolean;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isPlainObject = isPlainObject;
4
- function isObject(o) {
5
- return Object.prototype.toString.call(o) === '[object Object]';
6
- }
7
- function isPlainObject(o) {
8
- if (isObject(o) === false)
9
- return false;
10
- // If has modified constructor
11
- const ctor = o.constructor;
12
- if (ctor === undefined)
13
- return true;
14
- // If has modified prototype
15
- const prot = ctor.prototype;
16
- if (isObject(prot) === false)
17
- return false;
18
- // If constructor does not have an Object-specific method
19
- if (Object.prototype.hasOwnProperty.call(prot, 'isPrototypeOf') === false) {
20
- return false;
21
- }
22
- // Most likely a plain Object
23
- return true;
24
- }
25
- //# sourceMappingURL=is-plain-object.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"is-plain-object.js","sourceRoot":"","sources":["../../src/local-helpers/is-plain-object.ts"],"names":[],"mappings":";;AAIA,sCAkBC;AAtBD,SAAS,QAAQ,CAAC,CAAU;IACxB,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB,CAAC;AACnE,CAAC;AAED,SAAgB,aAAa,CAAC,CAAU;IACpC,IAAI,QAAQ,CAAC,CAAC,CAAC,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IAExC,8BAA8B;IAC9B,MAAM,IAAI,GAAI,CAA8B,CAAC,WAAW,CAAC;IACzD,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IAEpC,4BAA4B;IAC5B,MAAM,IAAI,GAAI,IAA+B,CAAC,SAAS,CAAC;IACxD,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,KAAK;QAAE,OAAO,KAAK,CAAC;IAE3C,yDAAyD;IACzD,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,eAAe,CAAC,KAAK,KAAK,EAAE,CAAC;QACxE,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,6BAA6B;IAC7B,OAAO,IAAI,CAAC;AAChB,CAAC"}
@@ -1 +0,0 @@
1
- export declare function lowerCaseFirst(input: string): string;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lowerCaseFirst = lowerCaseFirst;
4
- function lowerCaseFirst(input) {
5
- return input.charAt(0).toLowerCase() + input.slice(1);
6
- }
7
- //# sourceMappingURL=lower-case-first.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"lower-case-first.js","sourceRoot":"","sources":["../../src/local-helpers/lower-case-first.ts"],"names":[],"mappings":";;AAAA,wCAEC;AAFD,SAAgB,cAAc,CAAC,KAAa;IACxC,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC1D,CAAC"}
@@ -1 +0,0 @@
1
- export declare function paramCase(input: string): string;
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.paramCase = paramCase;
4
- const DEFAULT_SPLIT_REGEXP_1 = /([a-z0-9])([A-Z])/g;
5
- const DEFAULT_SPLIT_REGEXP_2 = /([A-Z])([A-Z][a-z])/g;
6
- const DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
7
- function paramCase(input) {
8
- const result = input
9
- .replace(DEFAULT_SPLIT_REGEXP_1, "$1\0$2")
10
- .replace(DEFAULT_SPLIT_REGEXP_2, "$1\0$2")
11
- .replace(DEFAULT_STRIP_REGEXP, "\0");
12
- let start = 0;
13
- let end = result.length;
14
- while (result.charAt(start) === "\0")
15
- start++;
16
- while (result.charAt(end - 1) === "\0")
17
- end--;
18
- return result.slice(start, end).split("\0").map((str) => str.toLowerCase()).join("-");
19
- }
20
- //# sourceMappingURL=param-case.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"param-case.js","sourceRoot":"","sources":["../../src/local-helpers/param-case.ts"],"names":[],"mappings":";;AAIA,8BAaC;AAjBD,MAAM,sBAAsB,GAAG,oBAAoB,CAAC;AACpD,MAAM,sBAAsB,GAAG,sBAAsB,CAAC;AACtD,MAAM,oBAAoB,GAAG,cAAc,CAAC;AAE5C,SAAgB,SAAS,CAAC,KAAa;IACnC,MAAM,MAAM,GAAG,KAAK;SACf,OAAO,CAAC,sBAAsB,EAAE,QAAQ,CAAC;SACzC,OAAO,CAAC,sBAAsB,EAAE,QAAQ,CAAC;SACzC,OAAO,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC;IAEzC,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC;IAExB,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,IAAI;QAAE,KAAK,EAAE,CAAC;IAC9C,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,IAAI;QAAE,GAAG,EAAE,CAAC;IAE9C,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC1F,CAAC"}
@@ -1 +0,0 @@
1
- export declare function sleep(timeout: number): Promise<void>;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sleep = sleep;
4
- function sleep(timeout) {
5
- return new Promise((resolve) => {
6
- setTimeout(() => resolve(), timeout);
7
- });
8
- }
9
- //# sourceMappingURL=sleep.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sleep.js","sourceRoot":"","sources":["../../src/local-helpers/sleep.ts"],"names":[],"mappings":";;AAAA,sBAIC;AAJD,SAAgB,KAAK,CAAC,OAAe;IACjC,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;QACjC,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -1 +0,0 @@
1
- export declare function invariant(condition: unknown, message?: string): asserts condition;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.invariant = invariant;
4
- const isProduction = process.env.NODE_ENV === 'production';
5
- const prefix = 'Invariant failed';
6
- function invariant(condition, message) {
7
- if (condition) {
8
- return;
9
- }
10
- if (isProduction) {
11
- throw new Error(prefix);
12
- }
13
- throw new Error(message ? `${prefix}: ${message}` : prefix);
14
- }
15
- //# sourceMappingURL=tiny-invariant.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tiny-invariant.js","sourceRoot":"","sources":["../../src/local-helpers/tiny-invariant.ts"],"names":[],"mappings":";;AAGA,8BAaC;AAhBD,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC;AAC3D,MAAM,MAAM,GAAG,kBAAkB,CAAC;AAElC,SAAgB,SAAS,CACrB,SAAkB,EAClB,OAAgB;IAEhB,IAAI,SAAS,EAAE,CAAC;QACZ,OAAO;IACX,CAAC;IAED,IAAI,YAAY,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,KAAK,OAAO,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAChE,CAAC"}
@@ -1 +0,0 @@
1
- export declare function upperCaseFirst(input: string): string;
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.upperCaseFirst = upperCaseFirst;
4
- function upperCaseFirst(input) {
5
- return input.charAt(0).toUpperCase() + input.slice(1);
6
- }
7
- //# sourceMappingURL=upper-case-first.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"upper-case-first.js","sourceRoot":"","sources":["../../src/local-helpers/upper-case-first.ts"],"names":[],"mappings":";;AAAA,wCAEC;AAFD,SAAgB,cAAc,CAAC,KAAa;IACxC,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAC1D,CAAC"}
package/model-meta.d.ts DELETED
@@ -1 +0,0 @@
1
- export { default } from '.zenstack/model-meta';
package/model-meta.js DELETED
@@ -1,10 +0,0 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
-
4
- try {
5
- exports.default = require('.zenstack/model-meta').default;
6
- } catch {
7
- exports.default = function () {
8
- throw new Error('Generated model meta not found. Please run `zenstack generate` first.');
9
- };
10
- }
package/models.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from '.zenstack/models';
package/models.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('.zenstack/models');
package/types.d.ts DELETED
@@ -1,200 +0,0 @@
1
- import type { z } from 'zod';
2
- import { FieldInfo } from './cross';
3
- export type PrismaPromise<T> = Promise<T> & Record<string, (args?: any) => PrismaPromise<any>>;
4
- /**
5
- * Weakly-typed database access methods
6
- */
7
- export interface DbOperations {
8
- findMany(args?: unknown): Promise<any[]>;
9
- findFirst(args?: unknown): PrismaPromise<any>;
10
- findFirstOrThrow(args?: unknown): PrismaPromise<any>;
11
- findUnique(args: unknown): PrismaPromise<any>;
12
- findUniqueOrThrow(args: unknown): PrismaPromise<any>;
13
- create(args: unknown): Promise<any>;
14
- createMany(args: unknown): Promise<{
15
- count: number;
16
- }>;
17
- createManyAndReturn(args: unknown): Promise<unknown[]>;
18
- update(args: unknown): Promise<any>;
19
- updateMany(args: unknown): Promise<{
20
- count: number;
21
- }>;
22
- updateManyAndReturn(args: unknown): Promise<unknown[]>;
23
- upsert(args: unknown): Promise<any>;
24
- delete(args: unknown): Promise<any>;
25
- deleteMany(args?: unknown): Promise<{
26
- count: number;
27
- }>;
28
- aggregate(args: unknown): Promise<any>;
29
- groupBy(args: unknown): Promise<any>;
30
- count(args?: unknown): Promise<any>;
31
- subscribe(args?: unknown): Promise<any>;
32
- stream(args?: unknown): Promise<any>;
33
- check(args: unknown): Promise<boolean>;
34
- fields: Record<string, any>;
35
- }
36
- /**
37
- * Kinds of access policy
38
- */
39
- export type PolicyKind = 'allow' | 'deny';
40
- export type PolicyCrudKind = 'read' | 'create' | 'update' | 'delete';
41
- /**
42
- * Kinds of operations controlled by access policies
43
- */
44
- export type PolicyOperationKind = PolicyCrudKind | 'postUpdate';
45
- /**
46
- * Current login user info
47
- */
48
- export type AuthUser = Record<string, unknown>;
49
- /**
50
- * Context for database query
51
- */
52
- export type QueryContext = {
53
- /**
54
- * Current login user (provided by @see RequestHandlerOptions)
55
- */
56
- user?: AuthUser;
57
- /**
58
- * Pre-update value of the entity
59
- */
60
- preValue?: any;
61
- };
62
- /**
63
- * Context for checking operation allowability.
64
- */
65
- export type PermissionCheckerContext = {
66
- /**
67
- * Current user
68
- */
69
- user?: AuthUser;
70
- /**
71
- * Extra field value filters.
72
- */
73
- fieldValues?: Record<string, string | number | boolean>;
74
- };
75
- /**
76
- * Prisma contract for CRUD operations.
77
- */
78
- export type CrudContract = Record<string, DbOperations>;
79
- /**
80
- * Prisma contract for database client.
81
- */
82
- export type DbClientContract = CrudContract & {
83
- $transaction: <T>(action: (tx: CrudContract) => Promise<T>, options?: unknown) => Promise<T>;
84
- };
85
- /**
86
- * Transaction isolation levels: https://www.prisma.io/docs/orm/prisma-client/queries/transactions#transaction-isolation-level
87
- */
88
- export type TransactionIsolationLevel = 'ReadUncommitted' | 'ReadCommitted' | 'RepeatableRead' | 'Snapshot' | 'Serializable';
89
- /**
90
- * Options for enhancing a PrismaClient.
91
- */
92
- export type EnhancementOptions = {
93
- /**
94
- * The kinds of enhancements to apply. By default all enhancements are applied.
95
- */
96
- kinds?: EnhancementKind[];
97
- /**
98
- * Whether to log Prisma query
99
- */
100
- logPrismaQuery?: boolean;
101
- /**
102
- * Hook for transforming errors before they are thrown to the caller.
103
- */
104
- errorTransformer?: ErrorTransformer;
105
- /**
106
- * The `maxWait` option passed to `prisma.$transaction()` call for transactions initiated by ZenStack.
107
- */
108
- transactionMaxWait?: number;
109
- /**
110
- * The `timeout` option passed to `prisma.$transaction()` call for transactions initiated by ZenStack.
111
- */
112
- transactionTimeout?: number;
113
- /**
114
- * The `isolationLevel` option passed to `prisma.$transaction()` call for transactions initiated by ZenStack.
115
- */
116
- transactionIsolationLevel?: TransactionIsolationLevel;
117
- /**
118
- * The encryption options for using the `encrypted` enhancement.
119
- */
120
- encryption?: SimpleEncryption | CustomEncryption;
121
- /**
122
- * Options for data validation.
123
- */
124
- validation?: ValidationOptions;
125
- };
126
- /**
127
- * Context for creating enhanced `PrismaClient`
128
- */
129
- export type EnhancementContext<User extends AuthUser = AuthUser> = {
130
- user?: User;
131
- };
132
- /**
133
- * Kinds of enhancements to `PrismaClient`
134
- */
135
- export type EnhancementKind = 'password' | 'omit' | 'policy' | 'validation' | 'delegate' | 'encryption';
136
- /**
137
- * Function for transforming errors.
138
- */
139
- export type ErrorTransformer = (error: unknown) => unknown;
140
- /**
141
- * Zod schemas for validation
142
- */
143
- export type ZodSchemas = {
144
- /**
145
- * Zod schema for each model
146
- */
147
- models: Record<string, z.ZodSchema>;
148
- /**
149
- * Zod schema for Prisma input types for each model
150
- */
151
- input?: Record<string, Record<string, z.ZodSchema>>;
152
- };
153
- /**
154
- * Simple encryption settings for processing fields marked with `@encrypted`.
155
- */
156
- export type SimpleEncryption = {
157
- /**
158
- * The encryption key.
159
- */
160
- encryptionKey: Uint8Array;
161
- /**
162
- * Optional list of all decryption keys that were previously used to encrypt the data
163
- * , for supporting key rotation. The `encryptionKey` field value is automatically
164
- * included for decryption.
165
- *
166
- * When the encrypted data is persisted, a metadata object containing the digest of the
167
- * encryption key is stored alongside the data. This digest is used to quickly determine
168
- * the correct decryption key to use when reading the data.
169
- */
170
- decryptionKeys?: Uint8Array[];
171
- };
172
- /**
173
- * Custom encryption settings for processing fields marked with `@encrypted`.
174
- */
175
- export type CustomEncryption = {
176
- /**
177
- * Encryption function.
178
- */
179
- encrypt: (model: string, field: FieldInfo, plain: string) => Promise<string>;
180
- /**
181
- * Decryption function
182
- */
183
- decrypt: (model: string, field: FieldInfo, cipher: string) => Promise<string>;
184
- };
185
- /**
186
- * Options for data validation.
187
- */
188
- export type ValidationOptions = {
189
- /**
190
- * Whether to validate "update" operations based only on the input data. By default, ZenStack
191
- * validates the entity after a update operation completes (inside a transaction), and rejects
192
- * the operation if validation fails. This implies the entire entity needs to satisfy the
193
- * validation rules, even for fields that are not part of the update input data.
194
- *
195
- * You can use this option to toggle the behavior to only validate the input data.
196
- *
197
- * Default is `false`.
198
- */
199
- inputOnlyValidationForUpdate?: boolean;
200
- };
package/types.js DELETED
@@ -1,4 +0,0 @@
1
- "use strict";
2
- /* eslint-disable @typescript-eslint/no-explicit-any */
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- //# sourceMappingURL=types.js.map
package/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA,uDAAuD"}
package/validation.d.ts DELETED
@@ -1,24 +0,0 @@
1
- import { z } from 'zod';
2
- /**
3
- * Error indicating violations of field-level constraints
4
- */
5
- export declare class ValidationError {
6
- readonly message: string;
7
- constructor(message: string);
8
- }
9
- /**
10
- * Validate the given data with the given zod schema (for field-level constraints)
11
- */
12
- export declare function validate(validator: z.ZodType, data: unknown): void;
13
- /**
14
- * Check if the given object has all the given fields, not null or undefined
15
- * @param obj
16
- * @param fields
17
- * @returns
18
- */
19
- export declare function hasAllFields(obj: any, fields: string[]): boolean;
20
- /**
21
- * Check if the given objects have equal values for the given fields. Returns
22
- * false if either object is nullish or is not an object.
23
- */
24
- export declare function allFieldsEqual(obj1: any, obj2: any, fields: string[]): boolean;
package/validation.js DELETED
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ValidationError = void 0;
4
- exports.validate = validate;
5
- exports.hasAllFields = hasAllFields;
6
- exports.allFieldsEqual = allFieldsEqual;
7
- const zod_validation_error_1 = require("zod-validation-error");
8
- /**
9
- * Error indicating violations of field-level constraints
10
- */
11
- class ValidationError {
12
- constructor(message) {
13
- this.message = message;
14
- }
15
- }
16
- exports.ValidationError = ValidationError;
17
- /**
18
- * Validate the given data with the given zod schema (for field-level constraints)
19
- */
20
- function validate(validator, data) {
21
- try {
22
- validator.parse(data);
23
- }
24
- catch (err) {
25
- throw new ValidationError((0, zod_validation_error_1.fromZodError)(err).message);
26
- }
27
- }
28
- /**
29
- * Check if the given object has all the given fields, not null or undefined
30
- * @param obj
31
- * @param fields
32
- * @returns
33
- */
34
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
35
- function hasAllFields(obj, fields) {
36
- if (typeof obj !== 'object' || !obj) {
37
- return false;
38
- }
39
- return fields.every((f) => obj[f] !== undefined && obj[f] !== null);
40
- }
41
- /**
42
- * Check if the given objects have equal values for the given fields. Returns
43
- * false if either object is nullish or is not an object.
44
- */
45
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
46
- function allFieldsEqual(obj1, obj2, fields) {
47
- if (!obj1 || !obj2 || typeof obj1 !== 'object' || typeof obj2 !== 'object') {
48
- return false;
49
- }
50
- return fields.every((f) => obj1[f] === obj2[f]);
51
- }
52
- //# sourceMappingURL=validation.js.map