arkos 1.4.11-beta → 1.4.13-beta

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 (99) hide show
  1. package/dist/cjs/components/arkos-policy/index.js +38 -0
  2. package/dist/cjs/components/arkos-policy/index.js.map +1 -0
  3. package/dist/cjs/{types/arkos-prisma-input.bak.js → components/arkos-policy/types.js} +1 -1
  4. package/dist/cjs/components/arkos-policy/types.js.map +1 -0
  5. package/dist/cjs/exports/config.js +6 -0
  6. package/dist/cjs/exports/config.js.map +1 -0
  7. package/dist/cjs/modules/auth/auth.service.js +1 -1
  8. package/dist/cjs/modules/auth/auth.service.js.map +1 -1
  9. package/dist/cjs/modules/error-handler/error-handler.controller.js +1 -1
  10. package/dist/cjs/modules/error-handler/error-handler.controller.js.map +1 -1
  11. package/dist/cjs/modules/swagger/utils/get-open-api-login-html.js +288 -0
  12. package/dist/cjs/modules/swagger/utils/get-open-api-login-html.js.map +1 -0
  13. package/dist/cjs/types/arkos-config/utils.js +3 -0
  14. package/dist/cjs/types/arkos-config/utils.js.map +1 -0
  15. package/dist/cjs/types/arkos-prisma-input.js.map +1 -1
  16. package/dist/cjs/types/arkos.js +3 -0
  17. package/dist/cjs/types/arkos.js.map +1 -0
  18. package/dist/cjs/utils/arkos-router/utils/helpers/apply-arkos-router-proxy.js +152 -0
  19. package/dist/cjs/utils/arkos-router/utils/helpers/apply-arkos-router-proxy.js.map +1 -0
  20. package/dist/cjs/utils/cli/utils/cli.helpers.js +1 -1
  21. package/dist/cjs/utils/cli/utils/template-generator/templates/class-validator-dto-generator.js +208 -0
  22. package/dist/cjs/utils/cli/utils/template-generator/templates/class-validator-dto-generator.js.map +1 -1
  23. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-multiple-components.js +143 -39
  24. package/dist/cjs/utils/cli/utils/template-generator/templates/generate-multiple-components.js.map +1 -1
  25. package/dist/cjs/utils/cli/utils/template-generator/templates/policy-template.js +51 -0
  26. package/dist/cjs/utils/cli/utils/template-generator/templates/policy-template.js.map +1 -0
  27. package/dist/cjs/utils/cli/utils/template-generator/templates/zod-schema-generator.js +169 -0
  28. package/dist/cjs/utils/cli/utils/template-generator/templates/zod-schema-generator.js.map +1 -1
  29. package/dist/cjs/utils/features/api.features.js +0 -3
  30. package/dist/cjs/utils/features/api.features.js.map +1 -1
  31. package/dist/cjs/utils/helpers/api.features.helpers.js +20 -0
  32. package/dist/cjs/utils/helpers/api.features.helpers.js.map +1 -1
  33. package/dist/cjs/utils/helpers/exit-error.js +12 -0
  34. package/dist/cjs/utils/helpers/exit-error.js.map +1 -0
  35. package/dist/cjs/utils/helpers/prisma.helpers.js +1 -2
  36. package/dist/cjs/utils/helpers/prisma.helpers.js.map +1 -1
  37. package/dist/cjs/utils/initialize-app.js +52 -0
  38. package/dist/cjs/utils/initialize-app.js.map +1 -0
  39. package/dist/cjs/utils/setup-app.js +119 -0
  40. package/dist/cjs/utils/setup-app.js.map +1 -0
  41. package/dist/esm/components/arkos-policy/index.js +32 -0
  42. package/dist/esm/components/arkos-policy/index.js.map +1 -0
  43. package/dist/esm/components/arkos-policy/types.js +2 -0
  44. package/dist/esm/components/arkos-policy/types.js.map +1 -0
  45. package/dist/esm/exports/config.js +3 -0
  46. package/dist/esm/exports/config.js.map +1 -0
  47. package/dist/esm/modules/auth/auth.service.js +1 -1
  48. package/dist/esm/modules/auth/auth.service.js.map +1 -1
  49. package/dist/esm/modules/error-handler/error-handler.controller.js +1 -1
  50. package/dist/esm/modules/error-handler/error-handler.controller.js.map +1 -1
  51. package/dist/esm/modules/swagger/utils/get-open-api-login-html.js +285 -0
  52. package/dist/esm/modules/swagger/utils/get-open-api-login-html.js.map +1 -0
  53. package/dist/esm/types/arkos-config/utils.js +2 -0
  54. package/dist/esm/types/arkos-config/utils.js.map +1 -0
  55. package/dist/esm/types/arkos-prisma-input.js.map +1 -1
  56. package/dist/esm/types/arkos.js +2 -0
  57. package/dist/esm/types/arkos.js.map +1 -0
  58. package/dist/esm/utils/arkos-router/utils/helpers/apply-arkos-router-proxy.js +146 -0
  59. package/dist/esm/utils/arkos-router/utils/helpers/apply-arkos-router-proxy.js.map +1 -0
  60. package/dist/esm/utils/cli/utils/cli.helpers.js +1 -1
  61. package/dist/esm/utils/cli/utils/template-generator/templates/class-validator-dto-generator.js +208 -0
  62. package/dist/esm/utils/cli/utils/template-generator/templates/class-validator-dto-generator.js.map +1 -1
  63. package/dist/esm/utils/cli/utils/template-generator/templates/generate-multiple-components.js +143 -39
  64. package/dist/esm/utils/cli/utils/template-generator/templates/generate-multiple-components.js.map +1 -1
  65. package/dist/esm/utils/cli/utils/template-generator/templates/policy-template.js +45 -0
  66. package/dist/esm/utils/cli/utils/template-generator/templates/policy-template.js.map +1 -0
  67. package/dist/esm/utils/cli/utils/template-generator/templates/zod-schema-generator.js +169 -0
  68. package/dist/esm/utils/cli/utils/template-generator/templates/zod-schema-generator.js.map +1 -1
  69. package/dist/esm/utils/features/api.features.js +0 -3
  70. package/dist/esm/utils/features/api.features.js.map +1 -1
  71. package/dist/esm/utils/helpers/api.features.helpers.js +20 -0
  72. package/dist/esm/utils/helpers/api.features.helpers.js.map +1 -1
  73. package/dist/esm/utils/helpers/exit-error.js +6 -0
  74. package/dist/esm/utils/helpers/exit-error.js.map +1 -0
  75. package/dist/esm/utils/helpers/prisma.helpers.js +1 -2
  76. package/dist/esm/utils/helpers/prisma.helpers.js.map +1 -1
  77. package/dist/esm/utils/initialize-app.js +45 -0
  78. package/dist/esm/utils/initialize-app.js.map +1 -0
  79. package/dist/esm/utils/setup-app.js +113 -0
  80. package/dist/esm/utils/setup-app.js.map +1 -0
  81. package/dist/types/components/arkos-policy/index.d.ts +31 -0
  82. package/dist/types/components/arkos-policy/types.d.ts +21 -0
  83. package/dist/types/exports/config.d.ts +2 -0
  84. package/dist/types/modules/swagger/utils/get-open-api-login-html.d.ts +1 -0
  85. package/dist/types/types/arkos-config/utils.d.ts +68 -0
  86. package/dist/types/types/arkos-prisma-input.d.ts +1 -1
  87. package/dist/types/types/arkos.d.ts +31 -0
  88. package/dist/types/utils/arkos-router/utils/helpers/apply-arkos-router-proxy.d.ts +7 -0
  89. package/dist/types/utils/cli/utils/template-generator/templates/class-validator-dto-generator.d.ts +4 -0
  90. package/dist/types/utils/cli/utils/template-generator/templates/policy-template.d.ts +2 -0
  91. package/dist/types/utils/cli/utils/template-generator/templates/zod-schema-generator.d.ts +4 -0
  92. package/dist/types/utils/helpers/exit-error.d.ts +1 -0
  93. package/dist/types/utils/initialize-app.d.ts +3 -0
  94. package/dist/types/utils/setup-app.d.ts +2 -0
  95. package/package.json +55 -55
  96. package/dist/cjs/types/arkos-prisma-input.bak.js.map +0 -1
  97. package/dist/esm/types/arkos-prisma-input.bak.js +0 -2
  98. package/dist/esm/types/arkos-prisma-input.bak.js.map +0 -1
  99. package/dist/types/types/arkos-prisma-input.bak.d.ts +0 -237
@@ -0,0 +1,113 @@
1
+ import compression from "compression";
2
+ import { getArkosConfig } from "./helpers/arkos-config.helpers.js";
3
+ import rateLimit from "express-rate-limit";
4
+ import deepmerge from "./helpers/deepmerge.helper.js";
5
+ import cors from "cors";
6
+ import express from "express";
7
+ import cookieParser from "cookie-parser";
8
+ import { queryParser } from "./helpers/query-parser.helpers.js";
9
+ import { handleRequestLogs } from "../modules/base/base.middlewares.js";
10
+ import debuggerService from "../modules/debugger/debugger.service.js";
11
+ export default function setupApp(app) {
12
+ const config = getArkosConfig();
13
+ const middlewaresConfig = config?.middlewares;
14
+ if (middlewaresConfig?.compression !== false) {
15
+ if (typeof middlewaresConfig?.compression === "function") {
16
+ app.use(middlewaresConfig.compression);
17
+ }
18
+ else {
19
+ app.use(compression(middlewaresConfig?.compression || {}));
20
+ }
21
+ }
22
+ if (middlewaresConfig?.rateLimit !== false) {
23
+ if (typeof middlewaresConfig?.rateLimit === "function") {
24
+ app.use(middlewaresConfig.rateLimit);
25
+ }
26
+ else {
27
+ app.use(rateLimit(deepmerge({
28
+ windowMs: 60 * 1000,
29
+ limit: 300,
30
+ standardHeaders: "draft-7",
31
+ legacyHeaders: false,
32
+ handler: (_, res) => {
33
+ res.status(429).json({
34
+ message: "Too many requests, please try again later",
35
+ });
36
+ },
37
+ }, middlewaresConfig?.rateLimit || {})));
38
+ }
39
+ }
40
+ if (middlewaresConfig?.cors !== false) {
41
+ if (typeof middlewaresConfig?.cors === "function") {
42
+ app.use(middlewaresConfig.cors);
43
+ }
44
+ else {
45
+ app.use(cors(middlewaresConfig?.cors?.customHandler
46
+ ? middlewaresConfig.cors.customHandler
47
+ : deepmerge({
48
+ origin: (origin, cb) => {
49
+ const allowed = middlewaresConfig?.cors
50
+ ?.allowedOrigins;
51
+ if (allowed === "*")
52
+ cb(null, true);
53
+ else if (Array.isArray(allowed))
54
+ cb(null, !origin || allowed?.includes?.(origin));
55
+ else if (typeof allowed === "string")
56
+ cb(null, !origin || allowed === origin);
57
+ else
58
+ cb(null, false);
59
+ },
60
+ methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"],
61
+ allowedHeaders: [
62
+ "Content-Type",
63
+ "Authorization",
64
+ "Connection",
65
+ ],
66
+ credentials: true,
67
+ }, middlewaresConfig?.cors?.options || {})));
68
+ }
69
+ }
70
+ if (middlewaresConfig?.expressJson !== false) {
71
+ if (typeof middlewaresConfig?.expressJson === "function") {
72
+ app.use(middlewaresConfig.expressJson);
73
+ }
74
+ else {
75
+ app.use(express.json(middlewaresConfig?.expressJson || {}));
76
+ }
77
+ }
78
+ if (middlewaresConfig?.cookieParser !== false) {
79
+ if (typeof middlewaresConfig?.cookieParser === "function") {
80
+ app.use(middlewaresConfig.cookieParser);
81
+ }
82
+ else {
83
+ const params = Array.isArray(middlewaresConfig?.cookieParser)
84
+ ? middlewaresConfig.cookieParser
85
+ : [];
86
+ app.use(cookieParser(...params));
87
+ }
88
+ }
89
+ if (middlewaresConfig?.queryParser !== false) {
90
+ if (typeof middlewaresConfig?.queryParser === "function") {
91
+ app.use(middlewaresConfig.queryParser);
92
+ }
93
+ else {
94
+ app.use(queryParser(deepmerge({
95
+ parseNull: true,
96
+ parseUndefined: true,
97
+ parseBoolean: true,
98
+ parseNumber: true,
99
+ }, middlewaresConfig?.queryParser || {})));
100
+ }
101
+ }
102
+ if (middlewaresConfig?.requestLogger !== false) {
103
+ if (typeof middlewaresConfig?.requestLogger === "function") {
104
+ app.use(middlewaresConfig.requestLogger);
105
+ }
106
+ else {
107
+ app.use(handleRequestLogs);
108
+ }
109
+ }
110
+ app.use(debuggerService.logRequestInfo);
111
+ return app;
112
+ }
113
+ //# sourceMappingURL=setup-app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup-app.js","sourceRoot":"","sources":["../../../src/utils/setup-app.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,SAAS,MAAM,4BAA4B,CAAC;AACnD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,YAAY,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,eAAe,MAAM,sCAAsC,CAAC;AAEnE,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,GAAU;IACzC,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAEhC,MAAM,iBAAiB,GAAG,MAAM,EAAE,WAAW,CAAC;IAE9C,IAAI,iBAAiB,EAAE,WAAW,KAAK,KAAK,EAAE,CAAC;QAC7C,IAAI,OAAO,iBAAiB,EAAE,WAAW,KAAK,UAAU,EAAE,CAAC;YACzD,GAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;QACzC,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,iBAAiB,EAAE,WAAW,IAAI,EAAE,CAAC,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;IAED,IAAI,iBAAiB,EAAE,SAAS,KAAK,KAAK,EAAE,CAAC;QAC3C,IAAI,OAAO,iBAAiB,EAAE,SAAS,KAAK,UAAU,EAAE,CAAC;YACvD,GAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;QACvC,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,GAAG,CACL,SAAS,CACP,SAAS,CACP;gBACE,QAAQ,EAAE,EAAE,GAAG,IAAI;gBACnB,KAAK,EAAE,GAAG;gBACV,eAAe,EAAE,SAAS;gBAC1B,aAAa,EAAE,KAAK;gBACpB,OAAO,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE;oBAClB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;wBACnB,OAAO,EAAE,2CAA2C;qBACrD,CAAC,CAAC;gBACL,CAAC;aACF,EACD,iBAAiB,EAAE,SAAS,IAAI,EAAE,CACnC,CACF,CACF,CAAC;QACJ,CAAC;IACH,CAAC;IAED,IAAI,iBAAiB,EAAE,IAAI,KAAK,KAAK,EAAE,CAAC;QACtC,IAAI,OAAO,iBAAiB,EAAE,IAAI,KAAK,UAAU,EAAE,CAAC;YAClD,GAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;QAClC,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,GAAG,CACL,IAAI,CACF,iBAAiB,EAAE,IAAI,EAAE,aAAa;gBACpC,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,aAAa;gBACtC,CAAC,CAAC,SAAS,CACP;oBACE,MAAM,EAAE,CACN,MAAc,EACd,EAAgD,EAChD,EAAE;wBACF,MAAM,OAAO,GAAI,iBAAiB,EAAE,IAAY;4BAC9C,EAAE,cAAc,CAAC;wBAEnB,IAAI,OAAO,KAAK,GAAG;4BAAE,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;6BAC/B,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;4BAC7B,EAAE,CAAC,IAAI,EAAE,CAAC,MAAM,IAAI,OAAO,EAAE,QAAQ,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;6BAC9C,IAAI,OAAO,OAAO,KAAK,QAAQ;4BAClC,EAAE,CAAC,IAAI,EAAE,CAAC,MAAM,IAAI,OAAO,KAAK,MAAM,CAAC,CAAC;;4BACrC,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;oBACvB,CAAC;oBAED,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC;oBAC7D,cAAc,EAAE;wBACd,cAAc;wBACd,eAAe;wBACf,YAAY;qBACb;oBACD,WAAW,EAAE,IAAI;iBAClB,EACD,iBAAiB,EAAE,IAAI,EAAE,OAAO,IAAI,EAAE,CACvC,CACN,CACF,CAAC;QACJ,CAAC;IACH,CAAC;IAED,IAAI,iBAAiB,EAAE,WAAW,KAAK,KAAK,EAAE,CAAC;QAC7C,IAAI,OAAO,iBAAiB,EAAE,WAAW,KAAK,UAAU,EAAE,CAAC;YACzD,GAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;QACzC,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE,WAAW,IAAI,EAAE,CAAC,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC;IAED,IAAI,iBAAiB,EAAE,YAAY,KAAK,KAAK,EAAE,CAAC;QAC9C,IAAI,OAAO,iBAAiB,EAAE,YAAY,KAAK,UAAU,EAAE,CAAC;YAC1D,GAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;QAC1C,CAAC;aAAM,CAAC;YACN,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,iBAAiB,EAAE,YAAY,CAAC;gBAC3D,CAAC,CAAC,iBAAiB,CAAC,YAAY;gBAChC,CAAC,CAAC,EAAE,CAAC;YACP,GAAG,CAAC,GAAG,CAAC,YAAY,CAAC,GAAI,MAAc,CAAC,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;IAED,IAAI,iBAAiB,EAAE,WAAW,KAAK,KAAK,EAAE,CAAC;QAC7C,IAAI,OAAO,iBAAiB,EAAE,WAAW,KAAK,UAAU,EAAE,CAAC;YACzD,GAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;QACzC,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,GAAG,CACL,WAAW,CACT,SAAS,CACP;gBACE,SAAS,EAAE,IAAI;gBACf,cAAc,EAAE,IAAI;gBACpB,YAAY,EAAE,IAAI;gBAClB,WAAW,EAAE,IAAI;aAClB,EACD,iBAAiB,EAAE,WAAW,IAAI,EAAE,CACrC,CACF,CACF,CAAC;QACJ,CAAC;IACH,CAAC;IAED,IAAI,iBAAiB,EAAE,aAAa,KAAK,KAAK,EAAE,CAAC;QAC/C,IAAI,OAAO,iBAAiB,EAAE,aAAa,KAAK,UAAU,EAAE,CAAC;YAC3D,GAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC;QAC3C,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,GAAG,CAAC,GAAG,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;IAExC,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import compression from \"compression\";\nimport { Arkos } from \"../types/arkos\";\nimport { getArkosConfig } from \"./helpers/arkos-config.helpers\";\nimport rateLimit from \"express-rate-limit\";\nimport deepmerge from \"./helpers/deepmerge.helper\";\nimport cors from \"cors\";\nimport express from \"express\";\nimport cookieParser from \"cookie-parser\";\nimport { queryParser } from \"./helpers/query-parser.helpers\";\nimport { handleRequestLogs } from \"../modules/base/base.middlewares\";\nimport debuggerService from \"../modules/debugger/debugger.service\";\n\nexport default function setupApp(app: Arkos) {\n const config = getArkosConfig();\n\n const middlewaresConfig = config?.middlewares;\n\n if (middlewaresConfig?.compression !== false) {\n if (typeof middlewaresConfig?.compression === \"function\") {\n app.use(middlewaresConfig.compression);\n } else {\n app.use(compression(middlewaresConfig?.compression || {}));\n }\n }\n\n if (middlewaresConfig?.rateLimit !== false) {\n if (typeof middlewaresConfig?.rateLimit === \"function\") {\n app.use(middlewaresConfig.rateLimit);\n } else {\n app.use(\n rateLimit(\n deepmerge(\n {\n windowMs: 60 * 1000,\n limit: 300,\n standardHeaders: \"draft-7\",\n legacyHeaders: false,\n handler: (_, res) => {\n res.status(429).json({\n message: \"Too many requests, please try again later\",\n });\n },\n },\n middlewaresConfig?.rateLimit || {}\n )\n )\n );\n }\n }\n\n if (middlewaresConfig?.cors !== false) {\n if (typeof middlewaresConfig?.cors === \"function\") {\n app.use(middlewaresConfig.cors);\n } else {\n app.use(\n cors(\n middlewaresConfig?.cors?.customHandler\n ? middlewaresConfig.cors.customHandler\n : deepmerge(\n {\n origin: (\n origin: string,\n cb: (err: Error | null, allow?: boolean) => void\n ) => {\n const allowed = (middlewaresConfig?.cors as any)\n ?.allowedOrigins;\n\n if (allowed === \"*\") cb(null, true);\n else if (Array.isArray(allowed))\n cb(null, !origin || allowed?.includes?.(origin));\n else if (typeof allowed === \"string\")\n cb(null, !origin || allowed === origin);\n else cb(null, false);\n },\n\n methods: [\"GET\", \"POST\", \"PUT\", \"DELETE\", \"PATCH\", \"OPTIONS\"],\n allowedHeaders: [\n \"Content-Type\",\n \"Authorization\",\n \"Connection\",\n ],\n credentials: true,\n },\n middlewaresConfig?.cors?.options || {}\n )\n )\n );\n }\n }\n\n if (middlewaresConfig?.expressJson !== false) {\n if (typeof middlewaresConfig?.expressJson === \"function\") {\n app.use(middlewaresConfig.expressJson);\n } else {\n app.use(express.json(middlewaresConfig?.expressJson || {}));\n }\n }\n\n if (middlewaresConfig?.cookieParser !== false) {\n if (typeof middlewaresConfig?.cookieParser === \"function\") {\n app.use(middlewaresConfig.cookieParser);\n } else {\n const params = Array.isArray(middlewaresConfig?.cookieParser)\n ? middlewaresConfig.cookieParser\n : [];\n app.use(cookieParser(...(params as any))); // FIXME: check types correctly\n }\n }\n\n if (middlewaresConfig?.queryParser !== false) {\n if (typeof middlewaresConfig?.queryParser === \"function\") {\n app.use(middlewaresConfig.queryParser);\n } else {\n app.use(\n queryParser(\n deepmerge(\n {\n parseNull: true,\n parseUndefined: true,\n parseBoolean: true,\n parseNumber: true,\n },\n middlewaresConfig?.queryParser || {}\n )\n )\n );\n }\n }\n\n if (middlewaresConfig?.requestLogger !== false) {\n if (typeof middlewaresConfig?.requestLogger === \"function\") {\n app.use(middlewaresConfig.requestLogger);\n } else {\n app.use(handleRequestLogs);\n }\n }\n\n app.use(debuggerService.logRequestInfo);\n\n return app;\n}\n"]}
@@ -0,0 +1,31 @@
1
+ import { IArkosPolicy } from "./types";
2
+ /**
3
+ * Creates a typed policy for a Prisma model resource.
4
+ *
5
+ * Each `.rule()` call registers an action and returns the policy
6
+ * with a typed `can{Action}` permission checker and a typed `{Action}`
7
+ * entry — both passable to the `authentication` field on `ArkosRouteHook`
8
+ * and `ArkosRouter`, and callable for fine-grained permission checks.
9
+ *
10
+ * @param resource - The resource name in kebab-case (e.g. `"user"`, `"blog-post"`)
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const userPolicy = ArkosPolicy("user")
15
+ * .rule("Create", ["Admin", "Editor"])
16
+ * .rule("View", "*")
17
+ * .rule("Delete", ["Admin"]);
18
+ *
19
+ * // Pass to authentication field
20
+ * userRouter.post({ path: "/users", authentication: userPolicy.Create });
21
+ * userRouteHook.deleteOne({ authentication: userPolicy.Delete });
22
+ *
23
+ * // Fine-grained check
24
+ * if (userPolicy.canCreate(req.user)) { ... }
25
+ *
26
+ * export default userPolicy;
27
+ * ```
28
+ *
29
+ * @see {@link https://www.arkosjs.com/docs/api-referency/arkos-policy}
30
+ */
31
+ export declare function ArkosPolicy<TResource extends string>(resource: TResource): IArkosPolicy<TResource, never>;
@@ -0,0 +1,21 @@
1
+ import { User } from "../../types";
2
+ import { DetailedAccessControlRule } from "../../types/auth";
3
+ export type ArkosPolicyRule = string[] | DetailedAccessControlRule | "*";
4
+ export type PolicyAuthEntry<TResource extends string, TAction extends string> = {
5
+ readonly resource: TResource;
6
+ readonly action: TAction;
7
+ readonly rule: ArkosPolicyRule;
8
+ };
9
+ export type PolicyChecker = (user?: User) => Promise<boolean>;
10
+ type CanKey<TAction extends string> = `can${Capitalize<TAction>}`;
11
+ export type PolicyWithActions<TResource extends string, TActions extends string> = IArkosPolicy<TResource, TActions> & {
12
+ [K in TActions]: PolicyAuthEntry<TResource, K>;
13
+ } & {
14
+ [K in CanKey<TActions>]: PolicyChecker;
15
+ };
16
+ export interface IArkosPolicy<TResource extends string, TActions extends string = never> {
17
+ readonly __type: "ArkosPolicy";
18
+ readonly resource: TResource;
19
+ rule<TAction extends string>(action: TAction, config?: ArkosPolicyRule): PolicyWithActions<TResource, TActions | TAction>;
20
+ }
21
+ export {};
@@ -0,0 +1,2 @@
1
+ import { defineConfig } from "../utils/define-config";
2
+ export { defineConfig };
@@ -0,0 +1 @@
1
+ export default function getOpenApiLoginHtml(): string;
@@ -0,0 +1,68 @@
1
+ import { ArkosRequest } from "..";
2
+ import { AccessAction, DetailedAccessControlRule } from "../auth";
3
+ /** Context passed to `before` hooks of `authenticate`. */
4
+ export interface AuthenticateBeforeHookContext {
5
+ /** The incoming request object. */
6
+ req: ArkosRequest;
7
+ /** Bypasses core logic and jumps directly to `after` hooks. */
8
+ skip: () => void;
9
+ }
10
+ /** Context passed to `after` hooks of `authenticate`. */
11
+ export interface AuthenticateAfterHookContext {
12
+ /** The incoming request object. */
13
+ req: ArkosRequest;
14
+ }
15
+ /** Context passed to `onError` hooks of `authenticate`. */
16
+ export interface AuthenticateErrorHookContext {
17
+ /** The incoming request object. */
18
+ req: ArkosRequest;
19
+ /** The error thrown during authentication. */
20
+ error: unknown;
21
+ /** Suppresses the error and jumps to `after` hooks. */
22
+ skip: () => void;
23
+ }
24
+ export type AuthenticateHookHandler = (ctx: AuthenticateBeforeHookContext) => void | Promise<void>;
25
+ export type AuthenticateAfterHookHandler = (ctx: AuthenticateAfterHookContext) => void | Promise<void>;
26
+ export type AuthenticateErrorHookHandler = (ctx: AuthenticateErrorHookContext) => void | Promise<void>;
27
+ /** Context passed to `before` hooks of `authorize`. */
28
+ export interface AuthorizeBeforeHookContext {
29
+ /** The incoming request object. */
30
+ req: ArkosRequest;
31
+ /** The action being authorized (e.g. `"Create"`, `"Delete"`). */
32
+ action: AccessAction;
33
+ /** The resource being accessed in kebab-case (e.g. `"post"`, `"cart-item"`). */
34
+ resource: string;
35
+ /** The access control rule for this action. */
36
+ rule?: string[] | DetailedAccessControlRule | "*";
37
+ /** Bypasses core logic and jumps directly to `after` hooks. */
38
+ skip: () => void;
39
+ }
40
+ /** Context passed to `after` hooks of `authorize`. */
41
+ export interface AuthorizeAfterHookContext {
42
+ /** The incoming request object. */
43
+ req: ArkosRequest;
44
+ /** The action that was authorized (e.g. `"Create"`, `"Delete"`). */
45
+ action: AccessAction;
46
+ /** The resource that was accessed in kebab-case (e.g. `"post"`, `"cart-item"`). */
47
+ resource: string;
48
+ /** The access control rule that was applied. */
49
+ rule?: string[] | DetailedAccessControlRule | "*";
50
+ }
51
+ /** Context passed to `onError` hooks of `authorize`. */
52
+ export interface AuthorizeErrorHookContext {
53
+ /** The incoming request object. */
54
+ req: ArkosRequest;
55
+ /** The error thrown during authorization. */
56
+ error: unknown;
57
+ /** The action being authorized (e.g. `"Create"`, `"Delete"`). */
58
+ action: AccessAction;
59
+ /** The resource being accessed in kebab-case (e.g. `"post"`, `"cart-item"`). */
60
+ resource: string;
61
+ /** The access control rule for this action. */
62
+ rule?: string[] | DetailedAccessControlRule | "*";
63
+ /** Suppresses the error and jumps to `after` hooks. */
64
+ skip: () => void;
65
+ }
66
+ export type AuthorizeHookHandler = (ctx: AuthorizeBeforeHookContext) => void | Promise<void>;
67
+ export type AuthorizeAfterHookHandler = (ctx: AuthorizeAfterHookContext) => void | Promise<void>;
68
+ export type AuthorizeErrorHookHandler = (ctx: AuthorizeErrorHookContext) => void | Promise<void>;
@@ -152,7 +152,7 @@ type FlattenRelations<T> = {
152
152
  * ]}
153
153
  * ```
154
154
  *
155
- * @see {@link https://wwww.arkosjs.com/docs/api-reference/arkos-prisma-input}
155
+ * @see {@link https://wwww.arkosjs.com/docs/reference/arkos-prisma-input}
156
156
  * @template T - The Prisma input type (e.g., Prisma.UserCreateInput)
157
157
  * @returns A flattened version of the input type with simplified relation handling
158
158
  */
@@ -0,0 +1,31 @@
1
+ import { Express } from "express";
2
+ import { IncomingMessage, Server, ServerResponse } from "http";
3
+ import { IArkosRouter } from "../exports";
4
+ type ArkosRouterMethods = "get" | "post" | "put" | "patch" | "delete" | "options" | "head" | "all" | "use" | "trace" | "route";
5
+ export interface Arkos extends Omit<Express, "listen" | ArkosRouterMethods>, Pick<IArkosRouter, ArkosRouterMethods> {
6
+ (req: IncomingMessage, res: ServerResponse): void;
7
+ /**
8
+ * Applies all loaded items to the app by adding them as middleware,
9
+ * routers, or handlers at the end of the stack.
10
+ *
11
+ * This ensures that Arkos internals always run after user middleware/routes.
12
+ * Automatically called before listen() if not called manually.
13
+ */
14
+ build(): Promise<this>;
15
+ /**
16
+ * Starts the server using Arkos-managed port and host configuration.
17
+ * Automatically calls build() if not called manually.
18
+ *
19
+ * @param callback Optional callback invoked once server starts
20
+ */
21
+ listen(callback?: (error?: Error) => void): Promise<Server>;
22
+ /**
23
+ * Starts the server using Arkos-managed port and host configuration.
24
+ * app.build() must be called before this.
25
+ *
26
+ * @param server {Server} - Optional callback invoked once server starts
27
+ * @param callback Optional callback invoked once server starts
28
+ */
29
+ listen(server: Server, callback?: (error?: Error) => void): Promise<Server>;
30
+ }
31
+ export {};
@@ -0,0 +1,7 @@
1
+ import { RouterOptions } from "express";
2
+ export declare function applyArkosRouterProxy<T extends object>(target: T, options?: RouterOptions & {
3
+ prefix?: string | RegExp | Array<string | RegExp>;
4
+ openapi?: {
5
+ tags?: string[];
6
+ };
7
+ }, name?: "app" | "ArkosRouter()"): T;
@@ -12,6 +12,10 @@ export declare class ClassValidatorDtoGenerator {
12
12
  private generateClassValidatorFieldForUpdate;
13
13
  private getValidatorsForType;
14
14
  private mapPrismaTypeToTS;
15
+ generateLoginDto(_: TemplateOptions): string;
16
+ generateSignupDto(_: TemplateOptions): string;
17
+ generateUpdateMeDto(_: TemplateOptions): string;
18
+ generateUpdatePasswordDto(_: TemplateOptions): string;
15
19
  }
16
20
  declare const classValidatorDtoGenerator: ClassValidatorDtoGenerator;
17
21
  export default classValidatorDtoGenerator;
@@ -0,0 +1,2 @@
1
+ import { TemplateOptions } from "../../template-generators";
2
+ export declare function generatePolicyTemplate(options: TemplateOptions): string;
@@ -9,6 +9,10 @@ export declare class ZodSchemaGenerator {
9
9
  private generateFilterSchemas;
10
10
  private generateZodField;
11
11
  private mapPrismaTypeToZod;
12
+ generateLoginSchema(_: TemplateOptions): string;
13
+ generateSignupSchema(_: TemplateOptions): string;
14
+ generateUpdateMeSchema(_: TemplateOptions): string;
15
+ generateUpdatePasswordSchema(_: TemplateOptions): string;
12
16
  }
13
17
  declare const zodSchemaGenerator: ZodSchemaGenerator;
14
18
  export default zodSchemaGenerator;
@@ -0,0 +1 @@
1
+ export default function ExitError(message: any, code?: number): void;
@@ -0,0 +1,3 @@
1
+ import { Arkos } from "../types/arkos";
2
+ export default function initializeApp(app: Arkos): Arkos;
3
+ export declare function addGlobalErrorHandler(app: Arkos): Arkos;
@@ -0,0 +1,2 @@
1
+ import { Arkos } from "../types/arkos";
2
+ export default function setupApp(app: Arkos): Arkos;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arkos",
3
- "version": "1.4.11-beta",
3
+ "version": "1.4.13-beta",
4
4
  "description": "The Express & Prisma RESTful Framework",
5
5
  "main": "dist/cjs/exports/index.js",
6
6
  "module": "dist/esm/exports/index.js",
@@ -134,66 +134,66 @@
134
134
  "homepage": "https://www.arkosjs.com",
135
135
  "files": ["dist", "cli.js", "README.md"],
136
136
  "devDependencies": {
137
- "@babel/preset-typescript": "^7.27.1",
138
- "@scalar/express-api-reference": "^0.8.32",
139
- "@types/bcrypt": "^5.0.2",
140
- "@types/body-parser": "^1.19.5",
141
- "@types/compression": "^1.7.5",
142
- "@types/cookie-parser": "^1.4.8",
143
- "@types/cors": "^2.8.17",
144
- "@types/express": "^5.0.0",
145
- "@types/html-to-text": "^9.0.4",
146
- "@types/jest": "^29.5.14",
147
- "@types/jsonwebtoken": "^9.0.9",
137
+ "@babel/preset-typescript": "7.27.1",
138
+ "@scalar/express-api-reference": "0.8.32",
139
+ "@types/bcrypt": "5.0.2",
140
+ "@types/body-parser": "1.19.5",
141
+ "@types/compression": "1.7.5",
142
+ "@types/cookie-parser": "1.4.8",
143
+ "@types/cors": "2.8.17",
144
+ "@types/express": "5.0.0",
145
+ "@types/html-to-text": "9.0.4",
146
+ "@types/jest": "29.5.14",
147
+ "@types/jsonwebtoken": "9.0.9",
148
148
  "@types/multer": "2.0.0",
149
- "@types/node": "^22.13.13",
150
- "@types/nodemailer": "^6.4.17",
151
- "@types/pluralize": "^0.0.33",
152
- "@types/swagger-jsdoc": "^6.0.4",
153
- "@typescript-eslint/eslint-plugin": "^6.0.0",
154
- "@typescript-eslint/parser": "^6.0.0",
155
- "esbuild": "^0.25.1",
156
- "fast-glob": "^3.3.3",
157
- "jest": "^29.7.0",
158
- "knip": "^6.0.1",
159
- "mimetype": "^0.0.8",
160
- "openapi-types": "^12.1.3",
161
- "prisma": "^6.19.2",
162
- "ts-jest": "^29.3.1",
163
- "ts-prune": "^0.10.3",
164
- "tsx": "^4.20.3",
165
- "type-fest": "^4.41.0",
166
- "typescript": "^5.8.2",
167
- "vitest": "^3.2.4"
149
+ "@types/node": "22.13.13",
150
+ "@types/nodemailer": "6.4.17",
151
+ "@types/pluralize": "0.0.33",
152
+ "@types/swagger-jsdoc": "6.0.4",
153
+ "@typescript-eslint/eslint-plugin": "6.0.0",
154
+ "@typescript-eslint/parser": "6.0.0",
155
+ "esbuild": "0.25.1",
156
+ "fast-glob": "3.3.3",
157
+ "jest": "29.7.0",
158
+ "knip": "6.0.1",
159
+ "mimetype": "0.0.8",
160
+ "openapi-types": "12.1.3",
161
+ "prisma": "6.19.2",
162
+ "ts-jest": "29.3.1",
163
+ "ts-prune": "0.10.3",
164
+ "tsx": "4.20.3",
165
+ "type-fest": "4.41.0",
166
+ "typescript": "5.8.2",
167
+ "vitest": "3.2.4"
168
168
  },
169
169
  "dependencies": {
170
- "chokidar": "^4.0.3",
171
- "commander": "^13.1.0",
172
- "pluralize": "^8.0.0"
170
+ "chokidar": "4.0.3",
171
+ "commander": "13.1.0",
172
+ "pluralize": "8.0.0"
173
173
  },
174
174
  "peerDependencies": {
175
- "@prisma/client": "^6.19.2",
176
- "@scalar/express-api-reference": "^0.8.35",
177
- "bcryptjs": "^3.0.2",
178
- "class-transformer": "^0.5.1",
179
- "class-validator": "^0.14.1",
180
- "class-validator-jsonschema": "^5.0.2",
181
- "compression": "^1.8.0",
182
- "cookie-parser": "^1.4.7",
183
- "cors": "^2.8.5",
184
- "dotenv": "^16.4.7",
185
- "dotenv-expand": "^12.0.3",
186
- "express": "^4.22.1",
187
- "express-rate-limit": "^7.5.0",
188
- "html-to-text": "^9.0.5",
189
- "jsonwebtoken": "^9.0.2",
190
- "mimetype": "^0.0.8",
175
+ "@prisma/client": "6.19.2",
176
+ "@scalar/express-api-reference": "0.8.35",
177
+ "bcryptjs": "3.0.2",
178
+ "class-transformer": "0.5.1",
179
+ "class-validator": "0.14.1",
180
+ "class-validator-jsonschema": "5.0.2",
181
+ "compression": "1.8.0",
182
+ "cookie-parser": "1.4.7",
183
+ "cors": "2.8.5",
184
+ "dotenv": "16.4.7",
185
+ "dotenv-expand": "12.0.3",
186
+ "express": "4.22.1",
187
+ "express-rate-limit": "7.5.0",
188
+ "html-to-text": "9.0.5",
189
+ "jsonwebtoken": "9.0.2",
190
+ "mimetype": "0.0.8",
191
191
  "multer": "2.0.2",
192
- "nodemailer": "^6.10.0",
193
- "sharp": "^0.33.5",
194
- "swagger-jsdoc": "^6.2.8",
195
- "zod": "^3.24.2",
196
- "zod-to-json-schema": "^3.24.6"
192
+ "nodemailer": "6.10.0",
193
+ "sharp": "0.33.5",
194
+ "swagger-jsdoc": "6.2.8",
195
+ "zod": "3.24.2",
196
+ "zod-to-json-schema": "3.24.6"
197
197
  },
198
198
  "engines": {
199
199
  "node": ">=20.16"
@@ -1 +0,0 @@
1
- {"version":3,"file":"arkos-prisma-input.bak.js","sourceRoot":"","sources":["../../../src/types/arkos-prisma-input.bak.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Helper type to exclude properties from T that exist in U\n * Used internally by XOR to create mutually exclusive types\n */\ntype Without<T, U> = {\n [P in Exclude<keyof T, keyof U>]?: never;\n};\n/**\n * XOR (Exclusive OR) type for mutually exclusive union types\n * Ensures that properties from T and U cannot be mixed together\n * @see https://stackoverflow.com/questions/42123407/does-typescript-support-mutually-exclusive-types\n */\ntype XOR<T, U> = T extends object\n ? U extends object\n ? (Without<T, U> & U) | (Without<U, T> & T)\n : U\n : T;\n/**\n * Extract type from Prisma's Enumerable wrapper\n * Currently acts as identity but can be extended to handle array unwrapping\n */\n// type Unpack<T> = T extends Array<infer U> ? U : T extends (infer U)[] ? U : T;\ntype Unpack<T> = T;\n/**\n * Checks if a field is a Prisma relation field\n * A field is considered a relation if it has any of: create, connect, connectOrCreate, update, delete, disconnect\n * Handles optional fields by excluding undefined before checking\n * @template T - The type to check\n * @returns true if T is a relation field, false otherwise\n */\nexport type IsRelationField<T> =\n Exclude<T, undefined> extends\n | {\n create?: { id?: any } | { id?: any }[];\n }\n | {\n connect?: { id?: any } | { id?: any }[];\n }\n | {\n update?: { where?: { id?: any }; data?: any };\n }\n | {\n delete?: { where?: { id?: any } };\n }\n | {\n disconnect?: { where?: { id?: any } };\n }\n ? true\n : false;\n\n/**\n * Checks if a Prisma relation field is an array/many relation\n * Detects relations that support multiple records (one-to-many or many-to-many)\n * @template T - The relation field type\n * @returns true if it's an array relation, false otherwise\n */\nexport type IsArrayRelation<T> =\n Exclude<T, undefined> extends { createMany?: any }\n ? true\n : Exclude<T, undefined> extends { deleteMany?: any }\n ? true\n : false;\n\n/**\n * Extracts the create data type from a Prisma relation field\n * @template T - The relation field type\n * @returns The type used in the create operation, or never if not present\n */\nexport type ExtractCreateType<T> =\n Exclude<T, undefined> extends { create?: infer C }\n ? C extends Array<infer U>\n ? (U & {\n apiAction?: \"create\";\n })[]\n : C & {\n apiAction?: \"create\";\n }\n : never;\n\ntype ExtractConnectType<\n T,\n action extends \"connect\" | \"delete\" | \"udpate\" | \"disconnect\" | \"deleteMany\",\n> =\n Exclude<T, undefined> extends { [k in action]?: infer C }\n ? C extends Array<infer U>\n ? (U & {\n apiAction?: action;\n })[]\n : C & {\n apiAction?: action;\n }\n : never;\n/**\n * Extracts and merges the update data type from a Prisma relation field\n * Combines the 'where' clause and 'data' fields into a single type\n * @template T - The relation field type\n * @returns Merged type of where & data fields, or never if not present\n */\ntype ExtractUpdateType<T> = T extends {\n update?: infer U;\n}\n ? U extends Array<infer Item>\n ? Item extends {\n where: infer W;\n data: infer D;\n }\n ? ((W & D) & { apiAction?: \"update\" })[]\n : never\n : U extends {\n where: infer W;\n data: infer D;\n }\n ? (W & D) & { apiAction?: \"update\" }\n : never\n : never;\n\n/**\n * Creates a flattened union type for a single relation field\n * Combines all possible Prisma operations (create, connect, update, delete, etc.) into a discriminated union\n * Each variant includes an optional apiAction field for explicit operation specification\n * @template T - The Prisma relation field type\n */\ntype FlattenRelationField<T> =\n /**\n * Create Operation - Creates a new related entity\n * Extracts the 'create' data type and recursively flattens nested relations\n * @example { name: \"New Item\", apiAction?: \"create\" }\n */\n | (ExtractCreateType<T> extends never\n ? never\n : FlattenRelations<ExtractCreateType<T>>)\n /**\n * Connect Operation - Links to an existing entity using unique fields\n * Extracts the 'connect' data type (typically unique identifiers like id, email, etc.)\n * @example { id: 123, apiAction?: \"connect\" } or { email: \"user@example.com\", apiAction?: \"connect\" }\n */\n | (ExtractConnectType<T, \"connect\"> extends never\n ? never\n : FlattenRelations<ExtractConnectType<T, \"connect\">>)\n /**\n * Update Operation - Modifies an existing related entity\n * Combines the 'where' clause and 'data' fields into a single flat object\n * @example { id: 123, name: \"Updated Name\", apiAction?: \"update\" }\n */\n | (ExtractUpdateType<T> extends never\n ? never\n : FlattenRelations<ExtractUpdateType<T>> & {\n apiAction?: \"update\";\n })\n /**\n * Delete Operation - Removes a related entity from the database\n * Requires unique identifier(s) and explicit apiAction: \"delete\"\n * For arrays, automatically uses deleteMany; for singular relations uses delete\n * @example { id: 123, apiAction: \"delete\" }\n */\n | (T extends {\n delete?: any;\n }\n ? {\n apiAction: \"delete\";\n } & ExtractConnectType<T, \"delete\">\n : never)\n /**\n * Disconnect Operation - Breaks the relationship without deleting the entity\n * Requires unique identifier(s) and explicit apiAction: \"disconnect\"\n * Only available for optional relations\n * @example { id: 123, apiAction: \"disconnect\" }\n */\n | (T extends {\n disconnect?: any;\n }\n ? {\n apiAction: \"disconnect\";\n } & ExtractConnectType<T, \"disconnect\">\n : never)\n /**\n * Set Operation - Replaces all related entities with a new set\n * Typically used for many-to-many relations to completely replace the relation set\n * @example { id: 456, apiAction?: \"set\" }\n */\n | (T extends {\n set?: infer S;\n }\n ? Unpack<S> & {\n apiAction?: \"set\";\n }\n : never)\n /**\n * Delete Many Operation - Removes multiple related entities matching criteria\n * Requires unique identifier(s) and explicit apiAction: \"deleteMany\"\n * Used for bulk deletion of related records\n * @example { id: 123, apiAction: \"deleteMany\" }\n */\n | (T extends {\n deleteMany?: any;\n }\n ? {\n apiAction: \"deleteMany\";\n } & ExtractConnectType<T, \"deleteMany\">\n : never);\n\n/**\n * Ensures array relations only accept arrays, not single objects\n * For array relations (one-to-many, many-to-many), forces array type\n * For singular relations (one-to-one, many-to-one), keeps XOR behavior\n * @template T - The original Prisma field type\n * @template Flattened - The flattened relation field type\n */\ntype EnforceArrayRelation<T, Flattened> =\n IsArrayRelation<T> extends true\n ? // Array relation: Extract only array types from the union\n Flattened extends Array<any>\n ? Flattened\n : never\n : // Singular relation: Keep XOR behavior (can be object OR array)\n Exclude<XOR<Flattened, T>, \"AND\">;\n\ntype FlattenRelations<T> = {\n [K in keyof T]: IsRelationField<T[K]> extends true\n ? EnforceArrayRelation<T[K], FlattenRelationField<T[K]>>\n : T[K] extends object\n ? T[K] extends Date | null | undefined\n ? T[K]\n : FlattenRelations<T[K]>\n : T[K];\n};\n/**\n * Flattens Prisma relation inputs into a simpler, developer-friendly format\n *\n * Transforms Prisma's nested relation format:\n * ```typescript\n * { posts: { create: [...], connect: [...], update: [...] } }\n * ```\n *\n * Into a flattened format with optional apiAction discriminators:\n * ```typescript\n * { posts: [\n * { title: \"New Post\" }, // auto-detected as create\n * { id: 1 }, // auto-detected as connect\n * { id: 2, title: \"Updated\", apiAction: \"update\" }\n * ]}\n * ```\n *\n * Features:\n * - Preserves non-relation fields as-is\n * - Automatically detects operation type based on field presence\n * - Supports explicit apiAction for disambiguation\n * - Works recursively for deeply nested relations\n * - Enforces array-only types for array relations (one-to-many, many-to-many)\n * - Enforces mutual exclusivity between flattened and Prisma formats for singular relations\n *\n * @see {@link https://wwww.arkosjs.com/docs/api-reference/arkos-prisma-input}\n * @template T - The Prisma input type (e.g., Prisma.UserCreateInput)\n * @returns A flattened version of the input type with simplified relation handling\n *\n * @example\n * ```typescript\n * import { Prisma } from \"@prisma/client\";\n *\n * type FlatUserInput = ArkosPrismaInput<Prisma.UserCreateInput>;\n *\n * const user: FlatUserInput = {\n * name: \"John\",\n * email: \"john@example.com\",\n * posts: [\n * { title: \"My First Post\" }, // creates new post\n * { id: 1 }, // connects to existing post\n * { id: 2, title: \"Updated\" }, // updates existing post\n * { id: 3, apiAction: \"delete\" } // deletes post\n * ],\n * profile: { bio: \"Software developer\" } // singular relation (can be object or array)\n * };\n * ```\n */\nexport type ArkosPrismaInput<T> = FlattenRelations<T>;\n"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=arkos-prisma-input.bak.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"arkos-prisma-input.bak.js","sourceRoot":"","sources":["../../../src/types/arkos-prisma-input.bak.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Helper type to exclude properties from T that exist in U\n * Used internally by XOR to create mutually exclusive types\n */\ntype Without<T, U> = {\n [P in Exclude<keyof T, keyof U>]?: never;\n};\n/**\n * XOR (Exclusive OR) type for mutually exclusive union types\n * Ensures that properties from T and U cannot be mixed together\n * @see https://stackoverflow.com/questions/42123407/does-typescript-support-mutually-exclusive-types\n */\ntype XOR<T, U> = T extends object\n ? U extends object\n ? (Without<T, U> & U) | (Without<U, T> & T)\n : U\n : T;\n/**\n * Extract type from Prisma's Enumerable wrapper\n * Currently acts as identity but can be extended to handle array unwrapping\n */\n// type Unpack<T> = T extends Array<infer U> ? U : T extends (infer U)[] ? U : T;\ntype Unpack<T> = T;\n/**\n * Checks if a field is a Prisma relation field\n * A field is considered a relation if it has any of: create, connect, connectOrCreate, update, delete, disconnect\n * Handles optional fields by excluding undefined before checking\n * @template T - The type to check\n * @returns true if T is a relation field, false otherwise\n */\nexport type IsRelationField<T> =\n Exclude<T, undefined> extends\n | {\n create?: { id?: any } | { id?: any }[];\n }\n | {\n connect?: { id?: any } | { id?: any }[];\n }\n | {\n update?: { where?: { id?: any }; data?: any };\n }\n | {\n delete?: { where?: { id?: any } };\n }\n | {\n disconnect?: { where?: { id?: any } };\n }\n ? true\n : false;\n\n/**\n * Checks if a Prisma relation field is an array/many relation\n * Detects relations that support multiple records (one-to-many or many-to-many)\n * @template T - The relation field type\n * @returns true if it's an array relation, false otherwise\n */\nexport type IsArrayRelation<T> =\n Exclude<T, undefined> extends { createMany?: any }\n ? true\n : Exclude<T, undefined> extends { deleteMany?: any }\n ? true\n : false;\n\n/**\n * Extracts the create data type from a Prisma relation field\n * @template T - The relation field type\n * @returns The type used in the create operation, or never if not present\n */\nexport type ExtractCreateType<T> =\n Exclude<T, undefined> extends { create?: infer C }\n ? C extends Array<infer U>\n ? (U & {\n apiAction?: \"create\";\n })[]\n : C & {\n apiAction?: \"create\";\n }\n : never;\n\ntype ExtractConnectType<\n T,\n action extends \"connect\" | \"delete\" | \"udpate\" | \"disconnect\" | \"deleteMany\",\n> =\n Exclude<T, undefined> extends { [k in action]?: infer C }\n ? C extends Array<infer U>\n ? (U & {\n apiAction?: action;\n })[]\n : C & {\n apiAction?: action;\n }\n : never;\n/**\n * Extracts and merges the update data type from a Prisma relation field\n * Combines the 'where' clause and 'data' fields into a single type\n * @template T - The relation field type\n * @returns Merged type of where & data fields, or never if not present\n */\ntype ExtractUpdateType<T> = T extends {\n update?: infer U;\n}\n ? U extends Array<infer Item>\n ? Item extends {\n where: infer W;\n data: infer D;\n }\n ? ((W & D) & { apiAction?: \"update\" })[]\n : never\n : U extends {\n where: infer W;\n data: infer D;\n }\n ? (W & D) & { apiAction?: \"update\" }\n : never\n : never;\n\n/**\n * Creates a flattened union type for a single relation field\n * Combines all possible Prisma operations (create, connect, update, delete, etc.) into a discriminated union\n * Each variant includes an optional apiAction field for explicit operation specification\n * @template T - The Prisma relation field type\n */\ntype FlattenRelationField<T> =\n /**\n * Create Operation - Creates a new related entity\n * Extracts the 'create' data type and recursively flattens nested relations\n * @example { name: \"New Item\", apiAction?: \"create\" }\n */\n | (ExtractCreateType<T> extends never\n ? never\n : FlattenRelations<ExtractCreateType<T>>)\n /**\n * Connect Operation - Links to an existing entity using unique fields\n * Extracts the 'connect' data type (typically unique identifiers like id, email, etc.)\n * @example { id: 123, apiAction?: \"connect\" } or { email: \"user@example.com\", apiAction?: \"connect\" }\n */\n | (ExtractConnectType<T, \"connect\"> extends never\n ? never\n : FlattenRelations<ExtractConnectType<T, \"connect\">>)\n /**\n * Update Operation - Modifies an existing related entity\n * Combines the 'where' clause and 'data' fields into a single flat object\n * @example { id: 123, name: \"Updated Name\", apiAction?: \"update\" }\n */\n | (ExtractUpdateType<T> extends never\n ? never\n : FlattenRelations<ExtractUpdateType<T>> & {\n apiAction?: \"update\";\n })\n /**\n * Delete Operation - Removes a related entity from the database\n * Requires unique identifier(s) and explicit apiAction: \"delete\"\n * For arrays, automatically uses deleteMany; for singular relations uses delete\n * @example { id: 123, apiAction: \"delete\" }\n */\n | (T extends {\n delete?: any;\n }\n ? {\n apiAction: \"delete\";\n } & ExtractConnectType<T, \"delete\">\n : never)\n /**\n * Disconnect Operation - Breaks the relationship without deleting the entity\n * Requires unique identifier(s) and explicit apiAction: \"disconnect\"\n * Only available for optional relations\n * @example { id: 123, apiAction: \"disconnect\" }\n */\n | (T extends {\n disconnect?: any;\n }\n ? {\n apiAction: \"disconnect\";\n } & ExtractConnectType<T, \"disconnect\">\n : never)\n /**\n * Set Operation - Replaces all related entities with a new set\n * Typically used for many-to-many relations to completely replace the relation set\n * @example { id: 456, apiAction?: \"set\" }\n */\n | (T extends {\n set?: infer S;\n }\n ? Unpack<S> & {\n apiAction?: \"set\";\n }\n : never)\n /**\n * Delete Many Operation - Removes multiple related entities matching criteria\n * Requires unique identifier(s) and explicit apiAction: \"deleteMany\"\n * Used for bulk deletion of related records\n * @example { id: 123, apiAction: \"deleteMany\" }\n */\n | (T extends {\n deleteMany?: any;\n }\n ? {\n apiAction: \"deleteMany\";\n } & ExtractConnectType<T, \"deleteMany\">\n : never);\n\n/**\n * Ensures array relations only accept arrays, not single objects\n * For array relations (one-to-many, many-to-many), forces array type\n * For singular relations (one-to-one, many-to-one), keeps XOR behavior\n * @template T - The original Prisma field type\n * @template Flattened - The flattened relation field type\n */\ntype EnforceArrayRelation<T, Flattened> =\n IsArrayRelation<T> extends true\n ? // Array relation: Extract only array types from the union\n Flattened extends Array<any>\n ? Flattened\n : never\n : // Singular relation: Keep XOR behavior (can be object OR array)\n Exclude<XOR<Flattened, T>, \"AND\">;\n\ntype FlattenRelations<T> = {\n [K in keyof T]: IsRelationField<T[K]> extends true\n ? EnforceArrayRelation<T[K], FlattenRelationField<T[K]>>\n : T[K] extends object\n ? T[K] extends Date | null | undefined\n ? T[K]\n : FlattenRelations<T[K]>\n : T[K];\n};\n/**\n * Flattens Prisma relation inputs into a simpler, developer-friendly format\n *\n * Transforms Prisma's nested relation format:\n * ```typescript\n * { posts: { create: [...], connect: [...], update: [...] } }\n * ```\n *\n * Into a flattened format with optional apiAction discriminators:\n * ```typescript\n * { posts: [\n * { title: \"New Post\" }, // auto-detected as create\n * { id: 1 }, // auto-detected as connect\n * { id: 2, title: \"Updated\", apiAction: \"update\" }\n * ]}\n * ```\n *\n * Features:\n * - Preserves non-relation fields as-is\n * - Automatically detects operation type based on field presence\n * - Supports explicit apiAction for disambiguation\n * - Works recursively for deeply nested relations\n * - Enforces array-only types for array relations (one-to-many, many-to-many)\n * - Enforces mutual exclusivity between flattened and Prisma formats for singular relations\n *\n * @see {@link https://wwww.arkosjs.com/docs/api-reference/arkos-prisma-input}\n * @template T - The Prisma input type (e.g., Prisma.UserCreateInput)\n * @returns A flattened version of the input type with simplified relation handling\n *\n * @example\n * ```typescript\n * import { Prisma } from \"@prisma/client\";\n *\n * type FlatUserInput = ArkosPrismaInput<Prisma.UserCreateInput>;\n *\n * const user: FlatUserInput = {\n * name: \"John\",\n * email: \"john@example.com\",\n * posts: [\n * { title: \"My First Post\" }, // creates new post\n * { id: 1 }, // connects to existing post\n * { id: 2, title: \"Updated\" }, // updates existing post\n * { id: 3, apiAction: \"delete\" } // deletes post\n * ],\n * profile: { bio: \"Software developer\" } // singular relation (can be object or array)\n * };\n * ```\n */\nexport type ArkosPrismaInput<T> = FlattenRelations<T>;\n"]}