@classytic/arc 2.11.4 → 2.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/README.md +16 -12
  2. package/dist/{BaseController-swXruJ2_.mjs → BaseController-DX_T-bDB.mjs} +388 -423
  3. package/dist/EventTransport-CT_52aWU.d.mts +34 -0
  4. package/dist/EventTransport-DLWoUMHy.mjs +103 -0
  5. package/dist/{ResourceRegistry-DkAeAuTX.mjs → ResourceRegistry-CTERg_2x.mjs} +139 -66
  6. package/dist/audit/index.d.mts +2 -2
  7. package/dist/audit/index.mjs +1 -1
  8. package/dist/auth/audit.d.mts +199 -0
  9. package/dist/auth/audit.mjs +288 -0
  10. package/dist/auth/index.d.mts +3 -3
  11. package/dist/auth/index.mjs +117 -191
  12. package/dist/{betterAuthOpenApi-DwxtK3uG.mjs → betterAuthOpenApi--M_i87dQ.mjs} +1 -1
  13. package/dist/buildHandler-olo-gt94.mjs +610 -0
  14. package/dist/cache/index.mjs +3 -3
  15. package/dist/cli/commands/describe.d.mts +89 -13
  16. package/dist/cli/commands/describe.mjs +56 -2
  17. package/dist/cli/commands/docs.mjs +2 -2
  18. package/dist/cli/commands/generate.mjs +147 -48
  19. package/dist/cli/commands/init.d.mts +13 -0
  20. package/dist/cli/commands/init.mjs +130 -87
  21. package/dist/cli/commands/introspect.mjs +8 -1
  22. package/dist/context/index.mjs +1 -1
  23. package/dist/core/index.d.mts +3 -3
  24. package/dist/core/index.mjs +5 -5
  25. package/dist/core-D72ia0EH.mjs +1399 -0
  26. package/dist/{createActionRouter-CIKOcNA7.mjs → createActionRouter-CEvzKcy8.mjs} +7 -20
  27. package/dist/createAggregationRouter-CyecOxnO.mjs +114 -0
  28. package/dist/{createApp-C9bRrqlX.mjs → createApp-XX2-N0Yd.mjs} +28 -22
  29. package/dist/{defineEvent-D1Ky9M1D.mjs → defineEvent-D5h7EvAx.mjs} +1 -1
  30. package/dist/docs/index.d.mts +1 -1
  31. package/dist/docs/index.mjs +2 -2
  32. package/dist/{elevation-DOFoxoDs.mjs → elevation-DgoeTyfX.mjs} +1 -1
  33. package/dist/errorHandler-Bk-AGhkU.mjs +174 -0
  34. package/dist/errorHandler-DFr45ZG4.d.mts +45 -0
  35. package/dist/errors-j4aJm1Wg.mjs +184 -0
  36. package/dist/{eventPlugin-Cts2-Tfj.mjs → eventPlugin-CaKTYkYM.mjs} +28 -4
  37. package/dist/{eventPlugin-DDJoNEPL.d.mts → eventPlugin-qXpqTebY.d.mts} +24 -1
  38. package/dist/events/index.d.mts +6 -6
  39. package/dist/events/index.mjs +11 -35
  40. package/dist/events/transports/redis-stream-entry.d.mts +1 -1
  41. package/dist/events/transports/redis.d.mts +1 -1
  42. package/dist/factory/index.d.mts +2 -2
  43. package/dist/factory/index.mjs +2 -2
  44. package/dist/{fields-BRjxOAFp.d.mts → fields-COhcH3fk.d.mts} +23 -2
  45. package/dist/hooks/index.d.mts +1 -1
  46. package/dist/hooks/index.mjs +1 -1
  47. package/dist/idempotency/index.d.mts +1 -1
  48. package/dist/idempotency/index.mjs +1 -20
  49. package/dist/idempotency/redis.mjs +1 -1
  50. package/dist/{index-rHjXmJar.d.mts → index-BTqLEvhu.d.mts} +163 -3
  51. package/dist/{index-CXXRbnf8.d.mts → index-BtW7qYwa.d.mts} +660 -326
  52. package/dist/{index-m8mOOlFW.d.mts → index-Ds61mrJE.d.mts} +50 -4
  53. package/dist/{index-D9t1KNaB.d.mts → index-Dz5IKsrE.d.mts} +360 -219
  54. package/dist/index.d.mts +6 -7
  55. package/dist/index.mjs +9 -10
  56. package/dist/integrations/event-gateway.d.mts +1 -1
  57. package/dist/integrations/event-gateway.mjs +1 -1
  58. package/dist/integrations/index.d.mts +1 -1
  59. package/dist/integrations/mcp/index.d.mts +2 -2
  60. package/dist/integrations/mcp/index.mjs +1 -1
  61. package/dist/integrations/mcp/testing.d.mts +1 -1
  62. package/dist/integrations/mcp/testing.mjs +1 -1
  63. package/dist/integrations/streamline.d.mts +60 -11
  64. package/dist/integrations/streamline.mjs +75 -85
  65. package/dist/integrations/websocket.mjs +2 -8
  66. package/dist/middleware/index.d.mts +1 -1
  67. package/dist/middleware/index.mjs +2 -2
  68. package/dist/migrations/index.d.mts +23 -3
  69. package/dist/migrations/index.mjs +0 -7
  70. package/dist/{multipartBody-CvTR1Un6.mjs → multipartBody-BOvVSVCD.mjs} +11 -8
  71. package/dist/{openapi-D7G1V7ex.mjs → openapi-CiOMVW1p.mjs} +143 -13
  72. package/dist/org/index.d.mts +2 -2
  73. package/dist/org/index.mjs +1 -1
  74. package/dist/permissions/index.d.mts +3 -3
  75. package/dist/permissions/index.mjs +3 -3
  76. package/dist/{permissions-gd_aUWrR.mjs → permissions-ohQyv50e.mjs} +404 -176
  77. package/dist/{pipe-DVoIheVC.mjs → pipe-Zr0KXjQe.mjs} +1 -1
  78. package/dist/pipeline/index.d.mts +1 -1
  79. package/dist/pipeline/index.mjs +1 -1
  80. package/dist/plugins/index.d.mts +16 -31
  81. package/dist/plugins/index.mjs +33 -13
  82. package/dist/plugins/response-cache.mjs +1 -1
  83. package/dist/plugins/tracing-entry.mjs +1 -1
  84. package/dist/presets/filesUpload.d.mts +4 -4
  85. package/dist/presets/filesUpload.mjs +6 -9
  86. package/dist/presets/index.d.mts +1 -1
  87. package/dist/presets/index.mjs +1 -1
  88. package/dist/presets/multiTenant.d.mts +1 -1
  89. package/dist/presets/multiTenant.mjs +2 -2
  90. package/dist/presets/search.d.mts +2 -2
  91. package/dist/presets/search.mjs +6 -8
  92. package/dist/{presets-Z7P5w4gF.mjs → presets-BbkjdPeH.mjs} +6 -28
  93. package/dist/{queryCachePlugin-Bq6bO6vc.mjs → queryCachePlugin-m1XsgAIJ.mjs} +3 -3
  94. package/dist/{redis-stream-xTGxB2bm.d.mts → redis-stream-D6HzR1Z_.d.mts} +1 -1
  95. package/dist/registry/index.d.mts +1 -1
  96. package/dist/registry/index.mjs +2 -2
  97. package/dist/{replyHelpers-ByllIXXV.mjs → replyHelpers-CK-FNO8E.mjs} +3 -21
  98. package/dist/{resourceToTools-CxNmI6xF.mjs → resourceToTools-C5coh64w.mjs} +224 -71
  99. package/dist/{routerShared-BqLRb5l7.mjs → routerShared-D6_fEGHh.mjs} +40 -36
  100. package/dist/{schemaIR-Dy2p4MxS.mjs → schemaIR-7Vl611Qs.mjs} +1 -1
  101. package/dist/schemas/index.d.mts +100 -30
  102. package/dist/schemas/index.mjs +86 -29
  103. package/dist/scim/index.d.mts +264 -0
  104. package/dist/scim/index.mjs +963 -0
  105. package/dist/scope/index.d.mts +3 -3
  106. package/dist/scope/index.mjs +4 -4
  107. package/dist/{sse-V7aXc3bW.mjs → sse-Bz-5ZeTt.mjs} +1 -1
  108. package/dist/{store-helpers-Cp4uKC1U.mjs → store-helpers-BkIN9-vu.mjs} +1 -1
  109. package/dist/testing/index.d.mts +2 -8
  110. package/dist/testing/index.mjs +16 -24
  111. package/dist/types/index.d.mts +4 -4
  112. package/dist/{types-D7KpfiL1.d.mts → types-BvqwCCSx.d.mts} +73 -25
  113. package/dist/{types-DDyTPc6y.d.mts → types-CTYvcwHe.d.mts} +195 -1
  114. package/dist/{types-AOD8fxIw.mjs → types-C_s5moIu.mjs} +117 -1
  115. package/dist/{types-BQ9TJQNy.d.mts → types-DQHFc8PM.d.mts} +1 -1
  116. package/dist/utils/index.d.mts +2 -2
  117. package/dist/utils/index.mjs +5 -5
  118. package/dist/{utils-CcYTj09l.mjs → utils-_h9B3c57.mjs} +1269 -1334
  119. package/dist/{versioning-DsglKfM_.d.mts → versioning-DTTvc80y.d.mts} +1 -1
  120. package/package.json +24 -34
  121. package/skills/arc/SKILL.md +147 -51
  122. package/skills/arc/references/agent-auth.md +238 -0
  123. package/skills/arc/references/api-reference.md +187 -0
  124. package/skills/arc/references/auth.md +354 -7
  125. package/skills/arc/references/enterprise-auth.md +94 -0
  126. package/skills/arc/references/events.md +8 -6
  127. package/skills/arc/references/mcp.md +2 -2
  128. package/skills/arc/references/multi-tenancy.md +11 -2
  129. package/skills/arc/references/production.md +10 -9
  130. package/skills/arc/references/scim.md +247 -0
  131. package/skills/arc/references/testing.md +1 -1
  132. package/skills/arc-code-review/SKILL.md +141 -0
  133. package/skills/arc-code-review/references/anti-patterns.md +911 -0
  134. package/skills/arc-code-review/references/arc-cheatsheet.md +380 -0
  135. package/skills/arc-code-review/references/migration-recipes.md +700 -0
  136. package/skills/arc-code-review/references/mongokit-migration.md +386 -0
  137. package/skills/arc-code-review/references/scaffolding.md +230 -0
  138. package/skills/arc-code-review/references/severity.md +127 -0
  139. package/dist/EventTransport-BFQjw9pB.mjs +0 -133
  140. package/dist/EventTransport-CYNUXdCJ.d.mts +0 -293
  141. package/dist/adapters/index.d.mts +0 -3
  142. package/dist/adapters/index.mjs +0 -2
  143. package/dist/adapters-DUUiiimH.mjs +0 -964
  144. package/dist/auth/mongoose.d.mts +0 -191
  145. package/dist/auth/mongoose.mjs +0 -73
  146. package/dist/core-CbcQRIch.mjs +0 -1054
  147. package/dist/errorHandler-BQm8ZxTK.mjs +0 -173
  148. package/dist/errorHandler-DEWmGWPz.d.mts +0 -114
  149. package/dist/errors-D5c-5BJL.mjs +0 -232
  150. package/dist/index-Rg8axYPz.d.mts +0 -370
  151. /package/dist/{HookSystem-CGsMd6oK.mjs → HookSystem-Iiebom92.mjs} +0 -0
  152. /package/dist/{actionPermissions-sUUKDhtP.mjs → actionPermissions-CyUkQu6O.mjs} +0 -0
  153. /package/dist/{caching-CheW3m-S.mjs → caching-SM8gghN6.mjs} +0 -0
  154. /package/dist/{constants-BhY1OHoH.mjs → constants-Cxde4rpC.mjs} +0 -0
  155. /package/dist/{elevation-BQQXZ_VR.d.mts → elevation-BXOWoGCF.d.mts} +0 -0
  156. /package/dist/{keys-CARyUjiR.mjs → keys-CGcCbNyu.mjs} +0 -0
  157. /package/dist/{loadResources-CPpkyKfM.mjs → loadResources-DBMQg_Aj.mjs} +0 -0
  158. /package/dist/{memory-DikHSvWa.mjs → memory-UBydS5ku.mjs} +0 -0
  159. /package/dist/{metrics-Csh4nsvv.mjs → metrics-Qnvwc-LQ.mjs} +0 -0
  160. /package/dist/{pluralize-CWP6MB39.mjs → pluralize-DQgqgifU.mjs} +0 -0
  161. /package/dist/{registry-D63ee7fl.mjs → registry-I-ogLgL9.mjs} +0 -0
  162. /package/dist/{requestContext-C5XeK3VA.mjs → requestContext-SSaaTgW8.mjs} +0 -0
  163. /package/dist/{schemaConverter-B0oKLuqI.mjs → schemaConverter-De34B1ZG.mjs} +0 -0
  164. /package/dist/{typeGuards-CcFZXgU7.mjs → typeGuards-BzkXkvVv.mjs} +0 -0
  165. /package/dist/{types-DV9WDfeg.mjs → types-D57iXYb8.mjs} +0 -0
  166. /package/dist/{versioning-CGPjkqAg.mjs → versioning-BUrT5aP4.mjs} +0 -0
@@ -1,964 +0,0 @@
1
- import { h as SYSTEM_FIELDS, m as RESERVED_QUERY_PARAMS } from "./constants-BhY1OHoH.mjs";
2
- //#region src/adapters/field-rule-helpers.ts
3
- /**
4
- * Merge constraint-style `fieldRules` into an `OpenApiSchemas` bag in place.
5
- *
6
- * Operates on the three schema slots that carry property maps — `createBody`,
7
- * `updateBody`, `response`. `listQuery` and `params` are skipped (their
8
- * constraint vocabulary is owned by the kit's query parser).
9
- *
10
- * Existing constraints on a property always win — the merge only fills in
11
- * gaps. Adapters that already walk `fieldRules` during base-schema assembly
12
- * can call this helper for free (the checks are no-ops when constraints
13
- * already exist).
14
- */
15
- function mergeFieldRuleConstraints(schemas, schemaOptions) {
16
- if (!schemas || typeof schemas !== "object") return;
17
- const rules = schemaOptions?.fieldRules;
18
- if (!rules || Object.keys(rules).length === 0) return;
19
- for (const slot of [
20
- "createBody",
21
- "updateBody",
22
- "response"
23
- ]) {
24
- const slotSchema = schemas[slot];
25
- if (!slotSchema || typeof slotSchema !== "object") continue;
26
- const properties = slotSchema.properties;
27
- if (!properties) continue;
28
- for (const [field, rule] of Object.entries(rules)) {
29
- const prop = properties[field];
30
- if (!prop || typeof prop !== "object") continue;
31
- if (rule.minLength != null && prop.minLength == null) prop.minLength = rule.minLength;
32
- if (rule.maxLength != null && prop.maxLength == null) prop.maxLength = rule.maxLength;
33
- if (rule.min != null && prop.minimum == null) prop.minimum = rule.min;
34
- if (rule.max != null && prop.maximum == null) prop.maximum = rule.max;
35
- if (rule.pattern != null && prop.pattern == null) prop.pattern = rule.pattern;
36
- if (rule.enum != null && prop.enum == null) prop.enum = rule.enum;
37
- if (rule.description != null && prop.description == null) prop.description = rule.description;
38
- if (rule.nullable === true) applyNullable(prop);
39
- }
40
- }
41
- }
42
- /**
43
- * Widen a JSON Schema property to also accept `null`.
44
- *
45
- * Handles the three ways a property can be typed:
46
- * - `type: 'string'` → `type: ['string', 'null']`
47
- * - `type: [...]` → append `'null'` if missing
48
- * - `anyOf: [...]` → append `{ type: 'null' }` branch if missing
49
- *
50
- * **Enum interaction:** when the widened prop also carries `enum: [...]`,
51
- * `null` is appended to the enum list too. AJV's `enum` keyword rejects
52
- * values not in the list regardless of the widened `type`, so
53
- * `{ type: ['string','null'], enum: ['a','b'] }` alone would still reject
54
- * `null`. The fix is `enum: ['a','b', null]`. (The `anyOf` branch dodges
55
- * this entirely — each branch scopes its own enum.)
56
- *
57
- * No-op when the schema already admits null (don't double-wrap) or has
58
- * no `type` / `anyOf` anchor to widen (e.g. Mixed — already accepts null).
59
- *
60
- * Mutates in place — callers already treat the slot schema as owned.
61
- * Exported so adapters that walk `fieldRules` inline (mongoose fallback,
62
- * drizzle post-process) can reuse the same widening logic.
63
- */
64
- function applyNullable(prop) {
65
- if (Array.isArray(prop.anyOf)) {
66
- if (!prop.anyOf.some((b) => b && typeof b === "object" && (b.type === "null" || b.const === null))) prop.anyOf.push({ type: "null" });
67
- return;
68
- }
69
- if (Array.isArray(prop.type)) {
70
- if (!prop.type.includes("null")) prop.type.push("null");
71
- widenEnumToIncludeNull(prop);
72
- return;
73
- }
74
- if (typeof prop.type === "string") {
75
- prop.type = [prop.type, "null"];
76
- widenEnumToIncludeNull(prop);
77
- return;
78
- }
79
- }
80
- /**
81
- * Append `null` to `enum` when present. Required because AJV's `enum`
82
- * keyword is independent of `type` — a value must appear in the enum
83
- * array verbatim even if the widened type says null is allowed.
84
- */
85
- function widenEnumToIncludeNull(prop) {
86
- if (!Array.isArray(prop.enum)) return;
87
- if (prop.enum.includes(null)) return;
88
- prop.enum = [...prop.enum, null];
89
- }
90
- //#endregion
91
- //#region src/adapters/types.ts
92
- /**
93
- * Check if value is a Mongoose model
94
- */
95
- function isMongooseModel(value) {
96
- return typeof value === "function" && value.prototype && "modelName" in value && "schema" in value;
97
- }
98
- /**
99
- * Check if value is a repository
100
- */
101
- function isRepository(value) {
102
- return typeof value === "object" && value !== null && "getAll" in value && "getById" in value && "create" in value && "update" in value && "delete" in value;
103
- }
104
- //#endregion
105
- //#region src/adapters/drizzle.ts
106
- const DRIZZLE_COLUMNS_SYMBOL = Symbol.for("drizzle:Columns");
107
- function getColumns(table) {
108
- const cols = table[DRIZZLE_COLUMNS_SYMBOL];
109
- if (!cols || typeof cols !== "object") return {};
110
- return cols;
111
- }
112
- function columnToJsonSchema(column) {
113
- const { dataType, columnType, enumValues, length } = column;
114
- if (dataType === "date") return {
115
- type: "string",
116
- format: "date-time"
117
- };
118
- if (dataType === "boolean") return { type: "boolean" };
119
- if (dataType === "json") return {
120
- type: "object",
121
- additionalProperties: true
122
- };
123
- if (dataType === "buffer") return {
124
- type: "string",
125
- contentEncoding: "base64"
126
- };
127
- if (dataType === "number" || dataType === "bigint") return { type: columnType === "SQLiteInteger" ? "integer" : "number" };
128
- if (dataType === "string") {
129
- const result = { type: "string" };
130
- if (Array.isArray(enumValues) && enumValues.length > 0) result.enum = [...enumValues];
131
- if (typeof length === "number" && length > 0) result.maxLength = length;
132
- return result;
133
- }
134
- return {};
135
- }
136
- function columnToFieldMetadata(column) {
137
- const { dataType, enumValues } = column;
138
- const meta = {
139
- type: (dataType && {
140
- number: "number",
141
- bigint: "number",
142
- string: "string",
143
- date: "date",
144
- boolean: "boolean",
145
- json: "object",
146
- buffer: "object"
147
- }[dataType]) ?? (enumValues?.length ? "enum" : "object"),
148
- required: !!column.notNull && !column.hasDefault
149
- };
150
- if (enumValues?.length) meta.enum = [...enumValues];
151
- if (typeof column.length === "number") meta.maxLength = column.length;
152
- return meta;
153
- }
154
- var DrizzleAdapter = class {
155
- type = "drizzle";
156
- name;
157
- table;
158
- repository;
159
- schemaGenerator;
160
- constructor(options) {
161
- if (!options.table || typeof options.table !== "object") throw new TypeError("DrizzleAdapter: Invalid table. Expected a Drizzle table created with sqliteTable / pgTable / mysqlTable.");
162
- if (!isRepository(options.repository)) throw new TypeError("DrizzleAdapter: Invalid repository. Expected an object implementing MinimalRepo (getAll / getById / create / update / delete).");
163
- this.table = options.table;
164
- this.repository = options.repository;
165
- this.schemaGenerator = options.schemaGenerator;
166
- this.name = options.name ?? "DrizzleAdapter";
167
- }
168
- /**
169
- * Introspect Drizzle columns into arc's schema metadata shape.
170
- */
171
- getSchemaMetadata() {
172
- const columns = getColumns(this.table);
173
- const fields = {};
174
- const indexes = [];
175
- for (const [name, column] of Object.entries(columns)) {
176
- fields[name] = columnToFieldMetadata(column);
177
- if (column.primary) indexes.push({
178
- fields: [name],
179
- unique: true
180
- });
181
- }
182
- return {
183
- name: this.name,
184
- fields,
185
- ...indexes.length > 0 ? { indexes } : {}
186
- };
187
- }
188
- /**
189
- * Generate OpenAPI schemas. Delegates to the user-provided
190
- * `schemaGenerator` when available (strongly recommended — that's where
191
- * field rules, omit lists, and param-type narrowing live). The built-in
192
- * fallback emits a permissive entity + CRUD body shape so routes still
193
- * register when no generator is provided.
194
- *
195
- * After the kit generator runs, arc merges constraint-style field rules
196
- * (`minLength`, `maxLength`, `min`, `max`, `pattern`, `enum`, `description`)
197
- * into the resulting property schemas so sqlitekit / pgkit behave
198
- * identically to mongoose here — rule-driven AJV constraints apply
199
- * regardless of backend.
200
- */
201
- generateSchemas(schemaOptions, context) {
202
- try {
203
- if (this.schemaGenerator) {
204
- const generated = this.schemaGenerator(this.table, schemaOptions, context);
205
- mergeFieldRuleConstraints(generated, schemaOptions);
206
- return generated;
207
- }
208
- const columns = getColumns(this.table);
209
- if (Object.keys(columns).length === 0) return null;
210
- const entityProperties = {};
211
- const inputProperties = {};
212
- const inputRequired = [];
213
- const updateProperties = {};
214
- const fieldRules = schemaOptions?.fieldRules ?? {};
215
- const readonlySet = new Set(schemaOptions?.readonlyFields ?? []);
216
- const optionalSet = new Set(schemaOptions?.optionalFields ?? []);
217
- const blocked = new Set([
218
- ...Object.entries(fieldRules).filter(([, rules]) => rules.systemManaged || rules.hidden).map(([field]) => field),
219
- ...schemaOptions?.excludeFields ?? [],
220
- ...schemaOptions?.hiddenFields ?? []
221
- ]);
222
- for (const [fieldName, column] of Object.entries(columns)) {
223
- const schema = columnToJsonSchema(column);
224
- entityProperties[fieldName] = schema;
225
- if (blocked.has(fieldName)) continue;
226
- if (column.primary && column.columnType === "SQLiteInteger") continue;
227
- if (!readonlySet.has(fieldName)) {
228
- inputProperties[fieldName] = schema;
229
- if (!!column.notNull && !column.hasDefault && !optionalSet.has(fieldName)) inputRequired.push(fieldName);
230
- updateProperties[fieldName] = schema;
231
- }
232
- }
233
- return {
234
- createBody: {
235
- type: "object",
236
- properties: inputProperties,
237
- required: inputRequired.length > 0 ? inputRequired : void 0,
238
- additionalProperties: true
239
- },
240
- updateBody: {
241
- type: "object",
242
- properties: updateProperties,
243
- additionalProperties: true
244
- },
245
- response: {
246
- type: "object",
247
- properties: entityProperties,
248
- additionalProperties: true
249
- }
250
- };
251
- } catch {
252
- return null;
253
- }
254
- }
255
- async healthCheck() {
256
- return typeof this.repository.getAll === "function";
257
- }
258
- };
259
- /**
260
- * Factory — preferred construction style for symmetry with
261
- * `createMongooseAdapter` / `createPrismaAdapter`.
262
- */
263
- function createDrizzleAdapter(options) {
264
- return new DrizzleAdapter(options);
265
- }
266
- //#endregion
267
- //#region src/adapters/interface.ts
268
- /**
269
- * Widen a permissive `AdapterRepositoryInput<TDoc>` to arc's strict
270
- * `RepositoryLike<TDoc>` view. Single-source escape hatch for the
271
- * filter-IR drift documented on `AdapterRepositoryInput`.
272
- *
273
- * Arc internals (audit / outbox / idempotency, BaseController) still see
274
- * the IR-aware `RepositoryLike`; only the call paths arc exercises are
275
- * shared between the two views, and those use the narrower
276
- * `Record<string, unknown>` filter shape both sides agree on.
277
- */
278
- function asRepositoryLike(input) {
279
- return input;
280
- }
281
- //#endregion
282
- //#region src/adapters/mongoose.ts
283
- /**
284
- * Mongoose data adapter with proper type safety
285
- *
286
- * @typeParam TDoc - The document type
287
- */
288
- var MongooseAdapter = class {
289
- type = "mongoose";
290
- name;
291
- model;
292
- repository;
293
- schemaGenerator;
294
- constructor(options) {
295
- if (!isMongooseModel(options.model)) throw new TypeError("MongooseAdapter: Invalid model. Expected Mongoose Model instance.\nUsage: createMongooseAdapter({ model: YourModel, repository: yourRepo })");
296
- if (!isRepository(options.repository)) throw new TypeError("MongooseAdapter: Invalid repository. Expected StandardRepo instance.\nUsage: createMongooseAdapter({ model: YourModel, repository: yourRepo })");
297
- this.model = options.model;
298
- this.repository = asRepositoryLike(options.repository);
299
- this.schemaGenerator = options.schemaGenerator;
300
- this.name = `MongooseAdapter<${options.model.modelName}>`;
301
- }
302
- /**
303
- * Get schema metadata from Mongoose model
304
- */
305
- getSchemaMetadata() {
306
- const paths = this.model.schema.paths;
307
- const fields = {};
308
- for (const [fieldName, schemaType] of Object.entries(paths)) {
309
- if (fieldName.startsWith("_") && fieldName !== "_id") continue;
310
- const typeInfo = schemaType;
311
- fields[fieldName] = {
312
- type: {
313
- String: "string",
314
- Number: "number",
315
- Boolean: "boolean",
316
- Date: "date",
317
- ObjectID: "objectId",
318
- ObjectId: "objectId",
319
- Array: "array",
320
- Mixed: "object",
321
- Buffer: "object",
322
- Embedded: "object"
323
- }[typeInfo.instance || "Mixed"] ?? "object",
324
- required: !!typeInfo.isRequired,
325
- ref: typeInfo.options?.ref
326
- };
327
- }
328
- return {
329
- name: this.model.modelName,
330
- fields,
331
- relations: this.extractRelations(paths)
332
- };
333
- }
334
- /**
335
- * Generate OpenAPI schemas from Mongoose model.
336
- *
337
- * If a `schemaGenerator` plugin was provided (e.g. MongoKit's buildCrudSchemasFromModel),
338
- * it is used instead of the built-in basic conversion.
339
- */
340
- generateSchemas(schemaOptions, context) {
341
- try {
342
- if (this.schemaGenerator) {
343
- const generated = this.schemaGenerator(this.model, schemaOptions, context);
344
- mergeFieldRuleConstraints(generated, schemaOptions);
345
- return generated;
346
- }
347
- const paths = this.model.schema.paths;
348
- const properties = {};
349
- const required = [];
350
- const fieldRules = schemaOptions?.fieldRules || {};
351
- const blockedFields = new Set([
352
- ...Object.entries(fieldRules).filter(([, rules]) => rules.systemManaged || rules.hidden).map(([field]) => field),
353
- ...schemaOptions?.excludeFields ?? [],
354
- ...schemaOptions?.hiddenFields ?? []
355
- ]);
356
- const readonlySet = new Set(schemaOptions?.readonlyFields ?? []);
357
- const optionalSet = new Set(schemaOptions?.optionalFields ?? []);
358
- for (const [fieldName, schemaType] of Object.entries(paths)) {
359
- if (fieldName.startsWith("__")) continue;
360
- if (blockedFields.has(fieldName)) continue;
361
- const typeInfo = schemaType;
362
- properties[fieldName] = this.mongooseTypeToOpenApi(typeInfo);
363
- const rule = fieldRules[fieldName];
364
- if (rule) {
365
- const prop = properties[fieldName];
366
- if (rule.minLength != null && prop.minLength == null) prop.minLength = rule.minLength;
367
- if (rule.maxLength != null && prop.maxLength == null) prop.maxLength = rule.maxLength;
368
- if (rule.min != null && prop.minimum == null) prop.minimum = rule.min;
369
- if (rule.max != null && prop.maximum == null) prop.maximum = rule.max;
370
- if (rule.pattern != null && prop.pattern == null) prop.pattern = rule.pattern;
371
- if (rule.enum != null && prop.enum == null) prop.enum = rule.enum;
372
- if (rule.description != null && prop.description == null) prop.description = rule.description;
373
- if (rule.nullable === true) applyNullable(prop);
374
- }
375
- if (typeInfo.isRequired && !optionalSet.has(fieldName) && !fieldRules[fieldName]?.optional) required.push(fieldName);
376
- }
377
- const readonlyForInput = new Set([...readonlySet]);
378
- for (const [field, rules] of Object.entries(fieldRules)) if (rules.immutable || rules.immutableAfterCreate) readonlyForInput.add(field);
379
- const inputBlockedSet = new Set([...SYSTEM_FIELDS, ...readonlyForInput]);
380
- const inputProperties = Object.fromEntries(Object.entries(properties).filter(([field]) => !inputBlockedSet.has(field)));
381
- const inputRequired = required.filter((field) => !inputBlockedSet.has(field) && !blockedFields.has(field));
382
- const immutableSet = /* @__PURE__ */ new Set();
383
- for (const [field, rules] of Object.entries(fieldRules)) if (rules.immutable || rules.immutableAfterCreate) immutableSet.add(field);
384
- const updateProperties = Object.fromEntries(Object.entries(inputProperties).filter(([field]) => !immutableSet.has(field)));
385
- return {
386
- createBody: {
387
- type: "object",
388
- properties: inputProperties,
389
- required: inputRequired.length > 0 ? inputRequired : void 0,
390
- additionalProperties: true
391
- },
392
- updateBody: {
393
- type: "object",
394
- properties: updateProperties,
395
- additionalProperties: true
396
- },
397
- response: {
398
- type: "object",
399
- properties,
400
- additionalProperties: true
401
- }
402
- };
403
- } catch {
404
- return null;
405
- }
406
- }
407
- /**
408
- * Extract relation metadata
409
- */
410
- extractRelations(paths) {
411
- const relations = {};
412
- for (const [fieldName, schemaType] of Object.entries(paths)) {
413
- const ref = schemaType.options?.ref;
414
- if (ref) relations[fieldName] = {
415
- type: "one-to-one",
416
- target: ref,
417
- foreignKey: fieldName
418
- };
419
- }
420
- return Object.keys(relations).length > 0 ? relations : void 0;
421
- }
422
- /**
423
- * Convert Mongoose type to OpenAPI type
424
- */
425
- mongooseTypeToOpenApi(typeInfo) {
426
- const instance = typeInfo.instance;
427
- const options = typeInfo.options || {};
428
- const baseType = {};
429
- switch (instance) {
430
- case "String":
431
- baseType.type = "string";
432
- if (options.enum) baseType.enum = options.enum;
433
- if (options.minlength) baseType.minLength = options.minlength;
434
- if (options.maxlength) baseType.maxLength = options.maxlength;
435
- break;
436
- case "Number":
437
- baseType.type = "number";
438
- if (options.min !== void 0) baseType.minimum = options.min;
439
- if (options.max !== void 0) baseType.maximum = options.max;
440
- break;
441
- case "Boolean":
442
- baseType.type = "boolean";
443
- break;
444
- case "Date":
445
- baseType.type = "string";
446
- break;
447
- case "ObjectID":
448
- case "ObjectId":
449
- baseType.type = "string";
450
- baseType.pattern = "^[a-f\\d]{24}$";
451
- break;
452
- case "Array": {
453
- baseType.type = "array";
454
- const ti = typeInfo;
455
- if (ti.$isMongooseDocumentArray && ti.schema) {
456
- const subSchema = ti.schema;
457
- const subProps = {};
458
- const subRequired = [];
459
- for (const [subField, subType] of Object.entries(subSchema.paths)) {
460
- if (subField.startsWith("_")) continue;
461
- subProps[subField] = this.mongooseTypeToOpenApi(subType);
462
- if (subType.isRequired) subRequired.push(subField);
463
- }
464
- baseType.items = {
465
- type: "object",
466
- properties: subProps,
467
- ...subRequired.length > 0 ? { required: subRequired } : {},
468
- additionalProperties: true
469
- };
470
- } else if (ti.embeddedSchemaType?.instance) baseType.items = this.mongooseTypeToOpenApi(ti.embeddedSchemaType);
471
- else baseType.items = {};
472
- break;
473
- }
474
- case "Mixed": break;
475
- case "Map":
476
- baseType.type = "object";
477
- baseType.additionalProperties = true;
478
- break;
479
- case "Embedded":
480
- case "SubDocument":
481
- baseType.type = "object";
482
- baseType.additionalProperties = true;
483
- break;
484
- case "Buffer":
485
- baseType.type = "string";
486
- baseType.format = "binary";
487
- break;
488
- case "Decimal128":
489
- baseType.type = "string";
490
- baseType.description = "Decimal128 (high-precision number as string)";
491
- break;
492
- case "UUID":
493
- baseType.type = "string";
494
- baseType.format = "uuid";
495
- break;
496
- default:
497
- baseType.type = "object";
498
- baseType.additionalProperties = true;
499
- }
500
- if (options.default === null) {
501
- applyNullable(baseType);
502
- baseType.default = null;
503
- }
504
- return baseType;
505
- }
506
- };
507
- function createMongooseAdapter(modelOrOptions, repository) {
508
- if (isMongooseModel(modelOrOptions)) {
509
- if (!repository) throw new TypeError("createMongooseAdapter: repository is required when using 2-arg form.\nUsage: createMongooseAdapter(Model, repository)");
510
- return new MongooseAdapter({
511
- model: modelOrOptions,
512
- repository
513
- });
514
- }
515
- return new MongooseAdapter(modelOrOptions);
516
- }
517
- //#endregion
518
- //#region src/adapters/prisma.ts
519
- /**
520
- * Prisma Query Parser - Converts URL parameters to Prisma query format
521
- *
522
- * Translates Arc's query format to Prisma's where/orderBy/take/skip structure.
523
- *
524
- * @example
525
- * ```typescript
526
- * const parser = new PrismaQueryParser();
527
- *
528
- * // URL: ?status=active&price[gte]=100&sort=-createdAt&page=2&limit=10
529
- * const prismaQuery = parser.toPrismaQuery(parsedQuery);
530
- * // Returns:
531
- * // {
532
- * // where: { status: 'active', price: { gte: 100 }, deletedAt: null },
533
- * // orderBy: { createdAt: 'desc' },
534
- * // take: 10,
535
- * // skip: 10,
536
- * // }
537
- * ```
538
- */
539
- var PrismaQueryParser = class {
540
- maxLimit;
541
- defaultLimit;
542
- softDeleteEnabled;
543
- softDeleteField;
544
- /** Map Arc operators to Prisma operators */
545
- operatorMap = {
546
- $eq: "equals",
547
- $ne: "not",
548
- $gt: "gt",
549
- $gte: "gte",
550
- $lt: "lt",
551
- $lte: "lte",
552
- $in: "in",
553
- $nin: "notIn",
554
- $regex: "contains",
555
- $exists: void 0
556
- };
557
- constructor(options = {}) {
558
- this.maxLimit = options.maxLimit ?? 1e3;
559
- this.defaultLimit = options.defaultLimit ?? 20;
560
- this.softDeleteEnabled = options.softDeleteEnabled ?? true;
561
- this.softDeleteField = options.softDeleteField ?? "deletedAt";
562
- }
563
- /**
564
- * Parse URL query parameters (delegates to ArcQueryParser format)
565
- */
566
- parse(query) {
567
- const q = query ?? {};
568
- const page = this.parseNumber(q.page, 1);
569
- const limit = Math.min(this.parseNumber(q.limit, this.defaultLimit), this.maxLimit);
570
- return {
571
- filters: this.parseFilters(q),
572
- limit,
573
- page,
574
- sort: this.parseSort(q.sort),
575
- search: q.search,
576
- select: this.parseSelect(q.select)
577
- };
578
- }
579
- /**
580
- * Convert ParsedQuery to Prisma query options
581
- */
582
- toPrismaQuery(parsed, policyFilters) {
583
- const where = {};
584
- if (parsed.filters) Object.assign(where, this.translateFilters(parsed.filters));
585
- if (policyFilters) Object.assign(where, this.translateFilters(policyFilters));
586
- if (this.softDeleteEnabled) where[this.softDeleteField] = null;
587
- const orderBy = parsed.sort ? Object.entries(parsed.sort).map(([field, dir]) => ({ [field]: dir === 1 ? "asc" : "desc" })) : void 0;
588
- const take = parsed.limit ?? this.defaultLimit;
589
- const skip = parsed.page ? (parsed.page - 1) * take : 0;
590
- const select = parsed.select ? Object.fromEntries(Object.entries(parsed.select).filter(([, v]) => v === 1).map(([k]) => [k, true])) : void 0;
591
- return {
592
- where: Object.keys(where).length > 0 ? where : void 0,
593
- orderBy: orderBy && orderBy.length > 0 ? orderBy : void 0,
594
- take,
595
- skip,
596
- select: select && Object.keys(select).length > 0 ? select : void 0
597
- };
598
- }
599
- /**
600
- * Translate Arc/MongoDB-style filters to Prisma where clause
601
- */
602
- translateFilters(filters) {
603
- const result = {};
604
- for (const [field, value] of Object.entries(filters)) {
605
- if (value === null || value === void 0) continue;
606
- if (typeof value === "object" && !Array.isArray(value)) {
607
- const prismaCondition = {};
608
- for (const [op, opValue] of Object.entries(value)) {
609
- if (op === "$exists") {
610
- result[field] = opValue ? { not: null } : null;
611
- continue;
612
- }
613
- const prismaOp = this.operatorMap[op];
614
- if (prismaOp) prismaCondition[prismaOp] = opValue;
615
- }
616
- if (Object.keys(prismaCondition).length > 0) result[field] = prismaCondition;
617
- } else result[field] = value;
618
- }
619
- return result;
620
- }
621
- parseNumber(value, defaultValue) {
622
- if (value === void 0 || value === null) return defaultValue;
623
- const num = parseInt(String(value), 10);
624
- return Number.isNaN(num) ? defaultValue : Math.max(1, num);
625
- }
626
- parseSort(value) {
627
- if (!value) return void 0;
628
- const sortStr = String(value);
629
- const result = {};
630
- for (const field of sortStr.split(",")) {
631
- const trimmed = field.trim();
632
- if (!trimmed || !/^-?[a-zA-Z_][a-zA-Z0-9_.]*$/.test(trimmed)) continue;
633
- if (trimmed.startsWith("-")) result[trimmed.slice(1)] = -1;
634
- else result[trimmed] = 1;
635
- }
636
- return Object.keys(result).length > 0 ? result : void 0;
637
- }
638
- parseSelect(value) {
639
- if (!value) return void 0;
640
- const result = {};
641
- for (const field of String(value).split(",")) {
642
- const trimmed = field.trim();
643
- if (!trimmed || !/^-?[a-zA-Z_][a-zA-Z0-9_.]*$/.test(trimmed)) continue;
644
- result[trimmed.startsWith("-") ? trimmed.slice(1) : trimmed] = trimmed.startsWith("-") ? 0 : 1;
645
- }
646
- return Object.keys(result).length > 0 ? result : void 0;
647
- }
648
- parseFilters(query) {
649
- const filters = {};
650
- const operators = {
651
- eq: "$eq",
652
- ne: "$ne",
653
- gt: "$gt",
654
- gte: "$gte",
655
- lt: "$lt",
656
- lte: "$lte",
657
- in: "$in",
658
- nin: "$nin",
659
- like: "$regex",
660
- contains: "$regex",
661
- exists: "$exists"
662
- };
663
- for (const [key, value] of Object.entries(query)) {
664
- if (RESERVED_QUERY_PARAMS.has(key) || value === void 0 || value === null) continue;
665
- const match = key.match(/^([a-zA-Z_][a-zA-Z0-9_.]*)(?:\[([a-z]+)\])?$/);
666
- if (!match) continue;
667
- const [, fieldName, operator] = match;
668
- if (!fieldName) continue;
669
- if (operator && operators[operator]) {
670
- if (!filters[fieldName]) filters[fieldName] = {};
671
- filters[fieldName][operators[operator]] = this.coerceValue(value, operator);
672
- } else if (!operator) filters[fieldName] = this.coerceValue(value);
673
- }
674
- return filters;
675
- }
676
- coerceValue(value, operator) {
677
- if (operator === "in" || operator === "nin") {
678
- if (Array.isArray(value)) return value.map((v) => this.coerceValue(v));
679
- if (typeof value === "string" && value.includes(",")) return value.split(",").map((v) => this.coerceValue(v.trim()));
680
- return [this.coerceValue(value)];
681
- }
682
- if (operator === "exists") return String(value).toLowerCase() === "true" || value === "1";
683
- if (value === "true") return true;
684
- if (value === "false") return false;
685
- if (value === "null") return null;
686
- if (typeof value === "string") {
687
- const num = Number(value);
688
- if (!Number.isNaN(num) && value.trim() !== "") return num;
689
- }
690
- return value;
691
- }
692
- };
693
- var PrismaAdapter = class {
694
- type = "prisma";
695
- name;
696
- repository;
697
- queryParser;
698
- client;
699
- modelName;
700
- dmmf;
701
- softDeleteEnabled;
702
- softDeleteField;
703
- constructor(options) {
704
- this.client = options.client;
705
- this.modelName = options.modelName;
706
- this.repository = options.repository;
707
- this.dmmf = options.dmmf;
708
- this.name = `prisma:${options.modelName}`;
709
- this.softDeleteEnabled = options.softDeleteEnabled ?? true;
710
- this.softDeleteField = options.softDeleteField ?? "deletedAt";
711
- this.queryParser = options.queryParser ?? new PrismaQueryParser({
712
- softDeleteEnabled: this.softDeleteEnabled,
713
- softDeleteField: this.softDeleteField
714
- });
715
- }
716
- /**
717
- * Parse URL query parameters and convert to Prisma query options
718
- */
719
- parseQuery(query, policyFilters) {
720
- const parsed = this.queryParser.parse(query);
721
- return this.queryParser.toPrismaQuery(parsed, policyFilters);
722
- }
723
- /**
724
- * Apply policy filters to existing Prisma where clause
725
- * Used for multi-tenant, ownership, and other security filters
726
- */
727
- applyPolicyFilters(where, policyFilters) {
728
- return {
729
- ...where,
730
- ...policyFilters
731
- };
732
- }
733
- generateSchemas(options) {
734
- if (!this.dmmf) return null;
735
- try {
736
- const model = this.dmmf.datamodel?.models?.find((m) => m.name.toLowerCase() === this.modelName.toLowerCase());
737
- if (!model) return null;
738
- return {
739
- entity: this.buildEntitySchema(model, options),
740
- createBody: this.buildCreateSchema(model, options),
741
- updateBody: this.buildUpdateSchema(model, options),
742
- params: {
743
- type: "object",
744
- properties: { id: { type: "string" } },
745
- required: ["id"]
746
- },
747
- listQuery: {
748
- type: "object",
749
- properties: {
750
- page: {
751
- type: "number",
752
- minimum: 1,
753
- description: "Page number for pagination"
754
- },
755
- limit: {
756
- type: "number",
757
- minimum: 1,
758
- maximum: 100,
759
- description: "Items per page"
760
- },
761
- sort: {
762
- type: "string",
763
- description: "Sort field (e.g., \"name\", \"-createdAt\")"
764
- }
765
- }
766
- }
767
- };
768
- } catch {
769
- return null;
770
- }
771
- }
772
- getSchemaMetadata() {
773
- if (!this.dmmf) return null;
774
- try {
775
- const model = this.dmmf.datamodel?.models?.find((m) => m.name.toLowerCase() === this.modelName.toLowerCase());
776
- if (!model) return null;
777
- const fields = {};
778
- for (const field of model.fields) fields[field.name] = this.convertPrismaFieldToMetadata(field);
779
- return {
780
- name: model.name,
781
- fields,
782
- indexes: model.uniqueIndexes?.map((idx) => ({
783
- fields: idx.fields,
784
- unique: true
785
- }))
786
- };
787
- } catch (_err) {
788
- return null;
789
- }
790
- }
791
- async validate(data) {
792
- if (!data || typeof data !== "object") return {
793
- valid: false,
794
- errors: [{
795
- field: "root",
796
- message: "Data must be an object"
797
- }]
798
- };
799
- if (this.dmmf) try {
800
- const model = this.dmmf.datamodel?.models?.find((m) => m.name.toLowerCase() === this.modelName.toLowerCase());
801
- if (model) {
802
- const requiredFields = model.fields.filter((f) => f.isRequired && !f.hasDefaultValue && !f.isGenerated);
803
- const errors = [];
804
- for (const field of requiredFields) if (!(field.name in data)) errors.push({
805
- field: field.name,
806
- message: `${field.name} is required`
807
- });
808
- if (errors.length > 0) return {
809
- valid: false,
810
- errors
811
- };
812
- }
813
- } catch (_err) {}
814
- return { valid: true };
815
- }
816
- async healthCheck() {
817
- try {
818
- const delegateName = this.modelName.charAt(0).toLowerCase() + this.modelName.slice(1);
819
- const delegate = this.client[delegateName];
820
- if (!delegate) return false;
821
- await delegate.findMany({ take: 1 });
822
- return true;
823
- } catch (_err) {
824
- return false;
825
- }
826
- }
827
- async close() {
828
- try {
829
- await this.client.$disconnect();
830
- } catch (_err) {}
831
- }
832
- buildEntitySchema(model, options) {
833
- const properties = {};
834
- const required = [];
835
- for (const field of model.fields) {
836
- if (this.shouldSkipField(field, options)) continue;
837
- properties[field.name] = this.convertPrismaFieldToJsonSchema(field);
838
- if (field.isRequired && !field.hasDefaultValue) required.push(field.name);
839
- }
840
- return {
841
- type: "object",
842
- properties,
843
- ...required.length > 0 && { required }
844
- };
845
- }
846
- buildCreateSchema(model, options) {
847
- const properties = {};
848
- const required = [];
849
- for (const field of model.fields) {
850
- if (field.isGenerated || field.relationName) continue;
851
- if (this.shouldSkipField(field, options)) continue;
852
- properties[field.name] = this.convertPrismaFieldToJsonSchema(field);
853
- if (field.isRequired && !field.hasDefaultValue) required.push(field.name);
854
- }
855
- return {
856
- type: "object",
857
- properties,
858
- ...required.length > 0 && { required }
859
- };
860
- }
861
- buildUpdateSchema(model, options) {
862
- const properties = {};
863
- for (const field of model.fields) {
864
- if (field.isGenerated || field.isId || field.relationName) continue;
865
- if (this.shouldSkipField(field, options)) continue;
866
- properties[field.name] = this.convertPrismaFieldToJsonSchema(field);
867
- }
868
- return {
869
- type: "object",
870
- properties
871
- };
872
- }
873
- shouldSkipField(field, options) {
874
- if (options?.excludeFields?.includes(field.name)) return true;
875
- if (field.name.startsWith("_")) return true;
876
- return false;
877
- }
878
- convertPrismaFieldToJsonSchema(field) {
879
- const schema = {};
880
- switch (field.type) {
881
- case "String":
882
- schema.type = "string";
883
- break;
884
- case "Int":
885
- case "BigInt":
886
- schema.type = "integer";
887
- break;
888
- case "Float":
889
- case "Decimal":
890
- schema.type = "number";
891
- break;
892
- case "Boolean":
893
- schema.type = "boolean";
894
- break;
895
- case "DateTime":
896
- schema.type = "string";
897
- schema.format = "date-time";
898
- break;
899
- case "Json":
900
- schema.type = "object";
901
- break;
902
- default: if (field.kind === "enum") {
903
- schema.type = "string";
904
- if (this.dmmf?.datamodel?.enums) {
905
- const enumDef = this.dmmf.datamodel.enums.find((e) => e.name === field.type);
906
- if (enumDef) schema.enum = enumDef.values.map((v) => v.name);
907
- }
908
- } else schema.type = "string";
909
- }
910
- if (field.isList) return {
911
- type: "array",
912
- items: schema
913
- };
914
- if (field.documentation) schema.description = field.documentation;
915
- return schema;
916
- }
917
- convertPrismaFieldToMetadata(field) {
918
- const metadata = {
919
- type: this.mapPrismaTypeToMetadataType(field.type, field.kind),
920
- required: field.isRequired,
921
- array: field.isList
922
- };
923
- if (field.isUnique) metadata.unique = true;
924
- if (field.hasDefaultValue) metadata.default = field.default;
925
- if (field.documentation) metadata.description = field.documentation;
926
- if (field.relationName) metadata.ref = field.type;
927
- return metadata;
928
- }
929
- mapPrismaTypeToMetadataType(type, kind) {
930
- if (kind === "enum") return "enum";
931
- switch (type) {
932
- case "String": return "string";
933
- case "Int":
934
- case "BigInt":
935
- case "Float":
936
- case "Decimal": return "number";
937
- case "Boolean": return "boolean";
938
- case "DateTime": return "date";
939
- case "Json": return "object";
940
- default: return "string";
941
- }
942
- }
943
- };
944
- /**
945
- * Factory function to create Prisma adapter
946
- *
947
- * @example
948
- * import { PrismaClient } from '@prisma/client';
949
- * import { createPrismaAdapter } from '@classytic/arc';
950
- *
951
- * const prisma = new PrismaClient();
952
- *
953
- * const userAdapter = createPrismaAdapter({
954
- * client: prisma,
955
- * modelName: 'user',
956
- * repository: userRepository,
957
- * dmmf: Prisma.dmmf, // Optional: for schema generation
958
- * });
959
- */
960
- function createPrismaAdapter(options) {
961
- return new PrismaAdapter(options);
962
- }
963
- //#endregion
964
- export { createMongooseAdapter as a, createDrizzleAdapter as c, MongooseAdapter as i, PrismaQueryParser as n, asRepositoryLike as o, createPrismaAdapter as r, DrizzleAdapter as s, PrismaAdapter as t };