@spfn/auth 0.1.0-alpha.88 → 0.2.0-beta.10

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 (152) hide show
  1. package/README.md +1385 -1199
  2. package/dist/config.d.ts +409 -0
  3. package/dist/config.js +244 -0
  4. package/dist/config.js.map +1 -0
  5. package/dist/dto-CRlgoCP5.d.ts +645 -0
  6. package/dist/errors.d.ts +196 -0
  7. package/dist/errors.js +173 -0
  8. package/dist/errors.js.map +1 -0
  9. package/dist/index.d.ts +287 -14
  10. package/dist/index.js +511 -6665
  11. package/dist/index.js.map +1 -1
  12. package/dist/nextjs/api.js +345 -0
  13. package/dist/nextjs/api.js.map +1 -0
  14. package/dist/{adapters/nextjs → nextjs}/server.d.ts +47 -65
  15. package/dist/nextjs/server.js +178 -0
  16. package/dist/nextjs/server.js.map +1 -0
  17. package/dist/server.d.ts +4444 -514
  18. package/dist/server.js +7977 -1210
  19. package/dist/server.js.map +1 -1
  20. package/migrations/0000_premium_famine.sql +292 -0
  21. package/migrations/meta/0000_snapshot.json +281 -46
  22. package/migrations/meta/_journal.json +2 -2
  23. package/package.json +37 -33
  24. package/dist/adapters/nextjs/api.d.ts +0 -446
  25. package/dist/adapters/nextjs/api.js +0 -3279
  26. package/dist/adapters/nextjs/api.js.map +0 -1
  27. package/dist/adapters/nextjs/server.js +0 -3645
  28. package/dist/adapters/nextjs/server.js.map +0 -1
  29. package/dist/lib/api/auth-codes-verify.d.ts +0 -37
  30. package/dist/lib/api/auth-codes-verify.js +0 -2949
  31. package/dist/lib/api/auth-codes-verify.js.map +0 -1
  32. package/dist/lib/api/auth-codes.d.ts +0 -37
  33. package/dist/lib/api/auth-codes.js +0 -2949
  34. package/dist/lib/api/auth-codes.js.map +0 -1
  35. package/dist/lib/api/auth-exists.d.ts +0 -38
  36. package/dist/lib/api/auth-exists.js +0 -2949
  37. package/dist/lib/api/auth-exists.js.map +0 -1
  38. package/dist/lib/api/auth-invitations-accept.d.ts +0 -38
  39. package/dist/lib/api/auth-invitations-accept.js +0 -2883
  40. package/dist/lib/api/auth-invitations-accept.js.map +0 -1
  41. package/dist/lib/api/auth-invitations-cancel.d.ts +0 -37
  42. package/dist/lib/api/auth-invitations-cancel.js +0 -2883
  43. package/dist/lib/api/auth-invitations-cancel.js.map +0 -1
  44. package/dist/lib/api/auth-invitations-delete.d.ts +0 -36
  45. package/dist/lib/api/auth-invitations-delete.js +0 -2883
  46. package/dist/lib/api/auth-invitations-delete.js.map +0 -1
  47. package/dist/lib/api/auth-invitations-resend.d.ts +0 -37
  48. package/dist/lib/api/auth-invitations-resend.js +0 -2883
  49. package/dist/lib/api/auth-invitations-resend.js.map +0 -1
  50. package/dist/lib/api/auth-invitations.d.ts +0 -109
  51. package/dist/lib/api/auth-invitations.js +0 -2887
  52. package/dist/lib/api/auth-invitations.js.map +0 -1
  53. package/dist/lib/api/auth-keys-rotate.d.ts +0 -37
  54. package/dist/lib/api/auth-keys-rotate.js +0 -2949
  55. package/dist/lib/api/auth-keys-rotate.js.map +0 -1
  56. package/dist/lib/api/auth-login.d.ts +0 -39
  57. package/dist/lib/api/auth-login.js +0 -2949
  58. package/dist/lib/api/auth-login.js.map +0 -1
  59. package/dist/lib/api/auth-logout.d.ts +0 -36
  60. package/dist/lib/api/auth-logout.js +0 -2949
  61. package/dist/lib/api/auth-logout.js.map +0 -1
  62. package/dist/lib/api/auth-me.d.ts +0 -50
  63. package/dist/lib/api/auth-me.js +0 -2949
  64. package/dist/lib/api/auth-me.js.map +0 -1
  65. package/dist/lib/api/auth-password.d.ts +0 -36
  66. package/dist/lib/api/auth-password.js +0 -2949
  67. package/dist/lib/api/auth-password.js.map +0 -1
  68. package/dist/lib/api/auth-register.d.ts +0 -38
  69. package/dist/lib/api/auth-register.js +0 -2949
  70. package/dist/lib/api/auth-register.js.map +0 -1
  71. package/dist/lib/api/index.d.ts +0 -356
  72. package/dist/lib/api/index.js +0 -3261
  73. package/dist/lib/api/index.js.map +0 -1
  74. package/dist/lib/config.d.ts +0 -70
  75. package/dist/lib/config.js +0 -64
  76. package/dist/lib/config.js.map +0 -1
  77. package/dist/lib/contracts/auth.d.ts +0 -302
  78. package/dist/lib/contracts/auth.js +0 -2951
  79. package/dist/lib/contracts/auth.js.map +0 -1
  80. package/dist/lib/contracts/index.d.ts +0 -3
  81. package/dist/lib/contracts/index.js +0 -3190
  82. package/dist/lib/contracts/index.js.map +0 -1
  83. package/dist/lib/contracts/invitation.d.ts +0 -243
  84. package/dist/lib/contracts/invitation.js +0 -2883
  85. package/dist/lib/contracts/invitation.js.map +0 -1
  86. package/dist/lib/crypto.d.ts +0 -76
  87. package/dist/lib/crypto.js +0 -127
  88. package/dist/lib/crypto.js.map +0 -1
  89. package/dist/lib/index.d.ts +0 -4
  90. package/dist/lib/index.js +0 -313
  91. package/dist/lib/index.js.map +0 -1
  92. package/dist/lib/session.d.ts +0 -68
  93. package/dist/lib/session.js +0 -126
  94. package/dist/lib/session.js.map +0 -1
  95. package/dist/lib/types/api.d.ts +0 -45
  96. package/dist/lib/types/api.js +0 -1
  97. package/dist/lib/types/api.js.map +0 -1
  98. package/dist/lib/types/index.d.ts +0 -3
  99. package/dist/lib/types/index.js +0 -2647
  100. package/dist/lib/types/index.js.map +0 -1
  101. package/dist/lib/types/schemas.d.ts +0 -45
  102. package/dist/lib/types/schemas.js +0 -2647
  103. package/dist/lib/types/schemas.js.map +0 -1
  104. package/dist/lib.js +0 -1
  105. package/dist/lib.js.map +0 -1
  106. package/dist/plugin.d.ts +0 -12
  107. package/dist/plugin.js +0 -9083
  108. package/dist/plugin.js.map +0 -1
  109. package/dist/server/entities/index.d.ts +0 -11
  110. package/dist/server/entities/index.js +0 -395
  111. package/dist/server/entities/index.js.map +0 -1
  112. package/dist/server/entities/invitations.d.ts +0 -241
  113. package/dist/server/entities/invitations.js +0 -184
  114. package/dist/server/entities/invitations.js.map +0 -1
  115. package/dist/server/entities/permissions.d.ts +0 -196
  116. package/dist/server/entities/permissions.js +0 -49
  117. package/dist/server/entities/permissions.js.map +0 -1
  118. package/dist/server/entities/role-permissions.d.ts +0 -107
  119. package/dist/server/entities/role-permissions.js +0 -115
  120. package/dist/server/entities/role-permissions.js.map +0 -1
  121. package/dist/server/entities/roles.d.ts +0 -196
  122. package/dist/server/entities/roles.js +0 -50
  123. package/dist/server/entities/roles.js.map +0 -1
  124. package/dist/server/entities/schema.d.ts +0 -14
  125. package/dist/server/entities/schema.js +0 -7
  126. package/dist/server/entities/schema.js.map +0 -1
  127. package/dist/server/entities/user-permissions.d.ts +0 -163
  128. package/dist/server/entities/user-permissions.js +0 -193
  129. package/dist/server/entities/user-permissions.js.map +0 -1
  130. package/dist/server/entities/user-public-keys.d.ts +0 -227
  131. package/dist/server/entities/user-public-keys.js +0 -156
  132. package/dist/server/entities/user-public-keys.js.map +0 -1
  133. package/dist/server/entities/user-social-accounts.d.ts +0 -189
  134. package/dist/server/entities/user-social-accounts.js +0 -149
  135. package/dist/server/entities/user-social-accounts.js.map +0 -1
  136. package/dist/server/entities/users.d.ts +0 -235
  137. package/dist/server/entities/users.js +0 -117
  138. package/dist/server/entities/users.js.map +0 -1
  139. package/dist/server/entities/verification-codes.d.ts +0 -191
  140. package/dist/server/entities/verification-codes.js +0 -49
  141. package/dist/server/entities/verification-codes.js.map +0 -1
  142. package/dist/server/routes/auth/index.d.ts +0 -10
  143. package/dist/server/routes/auth/index.js +0 -4460
  144. package/dist/server/routes/auth/index.js.map +0 -1
  145. package/dist/server/routes/index.d.ts +0 -6
  146. package/dist/server/routes/index.js +0 -6584
  147. package/dist/server/routes/index.js.map +0 -1
  148. package/dist/server/routes/invitations/index.d.ts +0 -10
  149. package/dist/server/routes/invitations/index.js +0 -4395
  150. package/dist/server/routes/invitations/index.js.map +0 -1
  151. package/migrations/0000_skinny_christian_walker.sql +0 -167
  152. /package/dist/{lib.d.ts → nextjs/api.d.ts} +0 -0
@@ -1,4395 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropNames = Object.getOwnPropertyNames;
3
- var __esm = (fn, res) => function __init() {
4
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
5
- };
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
-
11
- // src/server/helpers/jwt.ts
12
- var jwt_exports = {};
13
- __export(jwt_exports, {
14
- decodeToken: () => decodeToken,
15
- generateToken: () => generateToken,
16
- verifyClientToken: () => verifyClientToken,
17
- verifyKeyFingerprint: () => verifyKeyFingerprint,
18
- verifyToken: () => verifyToken
19
- });
20
- import jwt from "jsonwebtoken";
21
- import crypto from "crypto";
22
- function generateToken(payload) {
23
- return jwt.sign(payload, JWT_SECRET, {
24
- expiresIn: JWT_EXPIRES_IN
25
- });
26
- }
27
- function verifyToken(token) {
28
- return jwt.verify(token, JWT_SECRET);
29
- }
30
- function verifyClientToken(token, publicKeyB64, algorithm) {
31
- try {
32
- const publicKeyDER = Buffer.from(publicKeyB64, "base64");
33
- const publicKeyObject = crypto.createPublicKey({
34
- key: publicKeyDER,
35
- format: "der",
36
- type: "spki"
37
- });
38
- const decoded = jwt.verify(token, publicKeyObject, {
39
- algorithms: [algorithm],
40
- // Prevent algorithm confusion attacks
41
- issuer: "spfn-client"
42
- // Validate token issuer
43
- });
44
- if (typeof decoded === "string") {
45
- throw new Error("Invalid token format: expected object payload");
46
- }
47
- return decoded;
48
- } catch (error) {
49
- if (error instanceof jwt.TokenExpiredError) {
50
- throw new Error("Token has expired");
51
- }
52
- if (error instanceof jwt.JsonWebTokenError) {
53
- throw new Error("Invalid token signature");
54
- }
55
- throw new Error(`Token verification failed: ${error instanceof Error ? error.message : "Unknown error"}`);
56
- }
57
- }
58
- function decodeToken(token) {
59
- try {
60
- return jwt.decode(token);
61
- } catch {
62
- return null;
63
- }
64
- }
65
- function verifyKeyFingerprint(publicKeyB64, expectedFingerprint) {
66
- try {
67
- const publicKeyDER = Buffer.from(publicKeyB64, "base64");
68
- const fingerprint = crypto.createHash("sha256").update(publicKeyDER).digest("hex");
69
- return fingerprint === expectedFingerprint;
70
- } catch (error) {
71
- console.error("Failed to verify key fingerprint:", error);
72
- return false;
73
- }
74
- }
75
- var JWT_SECRET, JWT_EXPIRES_IN;
76
- var init_jwt = __esm({
77
- "src/server/helpers/jwt.ts"() {
78
- "use strict";
79
- JWT_SECRET = process.env.SPFN_AUTH_JWT_SECRET || // New prefixed version (recommended)
80
- process.env.JWT_SECRET || // Legacy fallback
81
- "dev-secret-key-change-in-production";
82
- JWT_EXPIRES_IN = process.env.SPFN_AUTH_JWT_EXPIRES_IN || // New prefixed version (recommended)
83
- process.env.JWT_EXPIRES_IN || // Legacy fallback
84
- "7d";
85
- }
86
- });
87
-
88
- // src/server/entities/schema.ts
89
- import { createFunctionSchema } from "@spfn/core/db";
90
- var authSchema;
91
- var init_schema = __esm({
92
- "src/server/entities/schema.ts"() {
93
- "use strict";
94
- authSchema = createFunctionSchema("@spfn/auth");
95
- }
96
- });
97
-
98
- // src/server/entities/roles.ts
99
- import { text, boolean, integer, index } from "drizzle-orm/pg-core";
100
- import { id, timestamps } from "@spfn/core/db";
101
- var roles;
102
- var init_roles = __esm({
103
- "src/server/entities/roles.ts"() {
104
- "use strict";
105
- init_schema();
106
- roles = authSchema.table(
107
- "roles",
108
- {
109
- // Primary key
110
- id: id(),
111
- // Role identifier (used in code, e.g., 'admin', 'editor')
112
- // Must be unique, lowercase, kebab-case recommended
113
- name: text("name").notNull().unique(),
114
- // Display name for UI (e.g., 'Administrator', 'Content Editor')
115
- displayName: text("display_name").notNull(),
116
- // Role description
117
- description: text("description"),
118
- // Built-in role flag
119
- // true: Core package roles (user, admin, superadmin) - cannot be deleted
120
- // false: Custom or preset roles - can be deleted
121
- isBuiltin: boolean("is_builtin").notNull().default(false),
122
- // System role flag
123
- // true: Defined in code (builtin or preset) - deletion restricted
124
- // false: Runtime created custom role - fully manageable
125
- isSystem: boolean("is_system").notNull().default(false),
126
- // Active status
127
- // false: Deactivated role (users cannot be assigned)
128
- isActive: boolean("is_active").notNull().default(true),
129
- // Priority level (higher = more privileged)
130
- // superadmin: 100, admin: 80, user: 10
131
- // Used for role hierarchy and conflict resolution
132
- priority: integer("priority").notNull().default(10),
133
- ...timestamps()
134
- },
135
- (table) => [
136
- index("roles_name_idx").on(table.name),
137
- index("roles_is_system_idx").on(table.isSystem),
138
- index("roles_is_active_idx").on(table.isActive),
139
- index("roles_is_builtin_idx").on(table.isBuiltin),
140
- index("roles_priority_idx").on(table.priority)
141
- ]
142
- );
143
- }
144
- });
145
-
146
- // src/server/entities/users.ts
147
- import { text as text2, timestamp, check, boolean as boolean2, bigint, index as index2 } from "drizzle-orm/pg-core";
148
- import { id as id2, timestamps as timestamps2 } from "@spfn/core/db";
149
- import { sql } from "drizzle-orm";
150
- var users;
151
- var init_users = __esm({
152
- "src/server/entities/users.ts"() {
153
- "use strict";
154
- init_roles();
155
- init_schema();
156
- users = authSchema.table(
157
- "users",
158
- {
159
- // Identity
160
- id: id2(),
161
- // Email address (unique identifier)
162
- // Used for: login, password reset, notifications
163
- email: text2("email").unique(),
164
- // Phone number in E.164 international format
165
- // Format: +[country code][number] (e.g., +821012345678)
166
- // Used for: SMS login, 2FA, notifications
167
- phone: text2("phone").unique(),
168
- // Authentication
169
- // Bcrypt password hash ($2b$10$[salt][hash], 60 chars)
170
- // Nullable to support OAuth-only accounts
171
- passwordHash: text2("password_hash"),
172
- // Force password change on next login
173
- // Use cases: initial setup, security breach, policy violation
174
- passwordChangeRequired: boolean2("password_change_required").notNull().default(false),
175
- // Authorization (Role-Based Access Control)
176
- // Foreign key to roles table
177
- // References built-in roles: user (default), admin, superadmin
178
- // Can also reference custom roles created at runtime
179
- roleId: bigint("role_id", { mode: "number" }).references(() => roles.id).notNull(),
180
- // Account status
181
- // - active: Normal operation (default)
182
- // - inactive: Deactivated (user request, dormant)
183
- // - suspended: Locked (security incident, ToS violation)
184
- status: text2(
185
- "status",
186
- {
187
- enum: ["active", "inactive", "suspended"]
188
- }
189
- ).notNull().default("active"),
190
- // Verification timestamps
191
- // null = unverified, timestamp = verified at this time
192
- // Email verification (via verification code or magic link)
193
- emailVerifiedAt: timestamp("email_verified_at", { withTimezone: true }),
194
- // Phone verification (via SMS OTP)
195
- phoneVerifiedAt: timestamp("phone_verified_at", { withTimezone: true }),
196
- // Metadata
197
- // Last successful login timestamp
198
- // Used for: security auditing, dormant account detection
199
- lastLoginAt: timestamp("last_login_at", { withTimezone: true }),
200
- ...timestamps2()
201
- },
202
- (table) => [
203
- // Database constraints
204
- // Ensure at least one identifier exists (email OR phone)
205
- check(
206
- "email_or_phone_check",
207
- sql`${table.email} IS NOT NULL OR ${table.phone} IS NOT NULL`
208
- ),
209
- // Indexes for query optimization
210
- index2("users_email_idx").on(table.email),
211
- index2("users_phone_idx").on(table.phone),
212
- index2("users_status_idx").on(table.status),
213
- index2("users_role_id_idx").on(table.roleId)
214
- ]
215
- );
216
- }
217
- });
218
-
219
- // src/server/entities/user-social-accounts.ts
220
- import { text as text3, timestamp as timestamp2, uniqueIndex } from "drizzle-orm/pg-core";
221
- import { id as id3, timestamps as timestamps3, foreignKey } from "@spfn/core/db";
222
- var userSocialAccounts;
223
- var init_user_social_accounts = __esm({
224
- "src/server/entities/user-social-accounts.ts"() {
225
- "use strict";
226
- init_users();
227
- init_schema();
228
- userSocialAccounts = authSchema.table(
229
- "user_social_accounts",
230
- {
231
- id: id3(),
232
- // Foreign key to users
233
- userId: foreignKey("user", () => users.id),
234
- // Provider info
235
- provider: text3(
236
- "provider",
237
- {
238
- enum: ["google", "github", "kakao", "naver"]
239
- }
240
- ).notNull(),
241
- providerUserId: text3("provider_user_id").notNull(),
242
- providerEmail: text3("provider_email"),
243
- // OAuth tokens (encrypted in production)
244
- accessToken: text3("access_token"),
245
- refreshToken: text3("refresh_token"),
246
- tokenExpiresAt: timestamp2("token_expires_at", { withTimezone: true }),
247
- ...timestamps3()
248
- },
249
- (table) => [
250
- // Unique constraint: one provider account per provider
251
- uniqueIndex("provider_user_unique_idx").on(table.provider, table.providerUserId)
252
- ]
253
- );
254
- }
255
- });
256
-
257
- // src/server/entities/user-public-keys.ts
258
- import { text as text4, timestamp as timestamp3, boolean as boolean3, index as index3 } from "drizzle-orm/pg-core";
259
- import { id as id4, foreignKey as foreignKey2 } from "@spfn/core/db";
260
- var userPublicKeys;
261
- var init_user_public_keys = __esm({
262
- "src/server/entities/user-public-keys.ts"() {
263
- "use strict";
264
- init_users();
265
- init_schema();
266
- userPublicKeys = authSchema.table(
267
- "user_public_keys",
268
- {
269
- id: id4(),
270
- // User reference
271
- userId: foreignKey2("user", () => users.id),
272
- // Key identification (client-generated UUID)
273
- keyId: text4("key_id").notNull().unique(),
274
- // Public key in Base64-encoded DER format (SPKI)
275
- publicKey: text4("public_key").notNull(),
276
- // Algorithm used (ES256 recommended, RS256 fallback)
277
- algorithm: text4("algorithm", {
278
- enum: ["ES256", "RS256"]
279
- }).notNull().default("ES256"),
280
- // Key fingerprint (SHA-256 hash for quick identification)
281
- fingerprint: text4("fingerprint").notNull(),
282
- // Key status
283
- isActive: boolean3("is_active").notNull().default(true),
284
- // Timestamps
285
- createdAt: timestamp3("created_at", { mode: "date", withTimezone: true }).notNull().defaultNow(),
286
- lastUsedAt: timestamp3("last_used_at", { mode: "date", withTimezone: true }),
287
- expiresAt: timestamp3("expires_at", { mode: "date", withTimezone: true }),
288
- // Revocation
289
- revokedAt: timestamp3("revoked_at", { mode: "date", withTimezone: true }),
290
- revokedReason: text4("revoked_reason")
291
- },
292
- (table) => [
293
- index3("user_public_keys_user_id_idx").on(table.userId),
294
- index3("user_public_keys_key_id_idx").on(table.keyId),
295
- index3("user_public_keys_active_idx").on(table.isActive),
296
- index3("user_public_keys_fingerprint_idx").on(table.fingerprint)
297
- ]
298
- );
299
- }
300
- });
301
-
302
- // src/server/entities/verification-codes.ts
303
- import { text as text5, timestamp as timestamp4, index as index4 } from "drizzle-orm/pg-core";
304
- import { id as id5, timestamps as timestamps4 } from "@spfn/core/db";
305
- var verificationCodes;
306
- var init_verification_codes = __esm({
307
- "src/server/entities/verification-codes.ts"() {
308
- "use strict";
309
- init_schema();
310
- verificationCodes = authSchema.table(
311
- "verification_codes",
312
- {
313
- id: id5(),
314
- // Target (email or phone)
315
- target: text5("target").notNull(),
316
- // Email address or E.164 phone number
317
- targetType: text5(
318
- "target_type",
319
- {
320
- enum: ["email", "phone"]
321
- }
322
- ).notNull(),
323
- // Code
324
- code: text5("code").notNull(),
325
- // 6-digit code by default (configurable)
326
- // Purpose
327
- purpose: text5(
328
- "purpose",
329
- {
330
- enum: ["registration", "login", "password_reset", "email_change", "phone_change"]
331
- }
332
- ).notNull(),
333
- // Expiry
334
- expiresAt: timestamp4("expires_at", { withTimezone: true }).notNull(),
335
- // Usage tracking
336
- usedAt: timestamp4("used_at", { withTimezone: true }),
337
- attempts: text5("attempts").notNull().default("0"),
338
- // Track failed verification attempts
339
- ...timestamps4()
340
- },
341
- (table) => [
342
- // Index for quick lookup by target and purpose
343
- index4("target_purpose_idx").on(table.target, table.purpose, table.expiresAt)
344
- ]
345
- );
346
- }
347
- });
348
-
349
- // src/server/entities/invitations.ts
350
- import { text as text6, timestamp as timestamp5, bigint as bigint2, index as index5, jsonb } from "drizzle-orm/pg-core";
351
- import { id as id6, timestamps as timestamps5 } from "@spfn/core/db";
352
- var invitations;
353
- var init_invitations = __esm({
354
- "src/server/entities/invitations.ts"() {
355
- "use strict";
356
- init_roles();
357
- init_users();
358
- init_schema();
359
- invitations = authSchema.table(
360
- "user_invitations",
361
- {
362
- // Primary key
363
- id: id6(),
364
- // Target email address for the invitation
365
- // Will become the user's email upon acceptance
366
- email: text6("email").notNull(),
367
- // Unique invitation token (UUID v4)
368
- // Used in invitation URL: /auth/invite/{token}
369
- // Single-use token that expires after acceptance
370
- token: text6("token").notNull().unique(),
371
- // Role to be assigned when invitation is accepted
372
- // Foreign key to roles table
373
- roleId: bigint2("role_id", { mode: "number" }).references(() => roles.id).notNull(),
374
- // User who created this invitation
375
- // Foreign key to users table
376
- // Used for: audit trail, permission checks
377
- invitedBy: bigint2("invited_by", { mode: "number" }).references(() => users.id).notNull(),
378
- // Invitation status
379
- // - pending: Invitation sent, awaiting acceptance
380
- // - accepted: User accepted and account created
381
- // - expired: Invitation expired (automatic)
382
- // - cancelled: Invitation cancelled by admin
383
- status: text6(
384
- "status",
385
- {
386
- enum: ["pending", "accepted", "expired", "cancelled"]
387
- }
388
- ).notNull().default("pending"),
389
- // Expiration timestamp (default: 7 days from creation)
390
- // Invitation cannot be accepted after this time
391
- // Background job should update status to 'expired'
392
- expiresAt: timestamp5("expires_at", { withTimezone: true }).notNull(),
393
- // Timestamp when invitation was accepted
394
- // null = not yet accepted
395
- // Used for: audit trail, analytics
396
- acceptedAt: timestamp5("accepted_at", { withTimezone: true }),
397
- // Timestamp when invitation was cancelled
398
- // null = not cancelled
399
- // Used for: audit trail
400
- cancelledAt: timestamp5("cancelled_at", { withTimezone: true }),
401
- // Additional metadata (JSONB)
402
- // Use cases:
403
- // - Custom welcome message
404
- // - Onboarding instructions
405
- // - Team/department assignment
406
- // - Custom fields for app-specific data
407
- // Example: { message: "Welcome!", department: "Engineering" }
408
- metadata: jsonb("metadata"),
409
- ...timestamps5()
410
- },
411
- (table) => [
412
- // Indexes for query optimization
413
- index5("invitations_token_idx").on(table.token),
414
- index5("invitations_email_idx").on(table.email),
415
- index5("invitations_status_idx").on(table.status),
416
- index5("invitations_invited_by_idx").on(table.invitedBy),
417
- index5("invitations_expires_at_idx").on(table.expiresAt),
418
- // For cleanup jobs
419
- index5("invitations_role_id_idx").on(table.roleId)
420
- ]
421
- );
422
- }
423
- });
424
-
425
- // src/server/entities/permissions.ts
426
- import { text as text7, boolean as boolean4, index as index6 } from "drizzle-orm/pg-core";
427
- import { id as id7, timestamps as timestamps6 } from "@spfn/core/db";
428
- var permissions;
429
- var init_permissions = __esm({
430
- "src/server/entities/permissions.ts"() {
431
- "use strict";
432
- init_schema();
433
- permissions = authSchema.table(
434
- "permissions",
435
- {
436
- // Primary key
437
- id: id7(),
438
- // Permission identifier (e.g., 'user:delete', 'post:publish')
439
- // Format: resource:action or namespace:resource:action
440
- // Must be unique
441
- name: text7("name").notNull().unique(),
442
- // Display name for UI
443
- displayName: text7("display_name").notNull(),
444
- // Permission description
445
- description: text7("description"),
446
- // Category for grouping (e.g., 'user', 'post', 'admin', 'system')
447
- category: text7("category"),
448
- // Built-in permission flag
449
- // true: Core package permissions - cannot be deleted
450
- // false: Custom or preset permissions
451
- isBuiltin: boolean4("is_builtin").notNull().default(false),
452
- // System permission flag
453
- // true: Defined in code (builtin or preset)
454
- // false: Runtime created custom permission
455
- isSystem: boolean4("is_system").notNull().default(false),
456
- // Active status
457
- // false: Deactivated permission (not enforced)
458
- isActive: boolean4("is_active").notNull().default(true),
459
- ...timestamps6()
460
- },
461
- (table) => [
462
- index6("permissions_name_idx").on(table.name),
463
- index6("permissions_category_idx").on(table.category),
464
- index6("permissions_is_system_idx").on(table.isSystem),
465
- index6("permissions_is_active_idx").on(table.isActive),
466
- index6("permissions_is_builtin_idx").on(table.isBuiltin)
467
- ]
468
- );
469
- }
470
- });
471
-
472
- // src/server/entities/role-permissions.ts
473
- import { bigint as bigint3, index as index7, unique } from "drizzle-orm/pg-core";
474
- import { id as id8, timestamps as timestamps7 } from "@spfn/core/db";
475
- var rolePermissions;
476
- var init_role_permissions = __esm({
477
- "src/server/entities/role-permissions.ts"() {
478
- "use strict";
479
- init_roles();
480
- init_permissions();
481
- init_schema();
482
- rolePermissions = authSchema.table(
483
- "role_permissions",
484
- {
485
- // Primary key
486
- id: id8(),
487
- // Foreign key to roles table
488
- roleId: bigint3("role_id", { mode: "number" }).notNull().references(() => roles.id, { onDelete: "cascade" }),
489
- // Foreign key to permissions table
490
- permissionId: bigint3("permission_id", { mode: "number" }).notNull().references(() => permissions.id, { onDelete: "cascade" }),
491
- ...timestamps7()
492
- },
493
- (table) => [
494
- // Indexes for query performance
495
- index7("role_permissions_role_id_idx").on(table.roleId),
496
- index7("role_permissions_permission_id_idx").on(table.permissionId),
497
- // Unique constraint: one role-permission pair only
498
- unique("role_permissions_unique").on(table.roleId, table.permissionId)
499
- ]
500
- );
501
- }
502
- });
503
-
504
- // src/server/entities/user-permissions.ts
505
- import { bigint as bigint4, boolean as boolean5, text as text8, timestamp as timestamp6, index as index8, unique as unique2 } from "drizzle-orm/pg-core";
506
- import { id as id9, timestamps as timestamps8 } from "@spfn/core/db";
507
- var userPermissions;
508
- var init_user_permissions = __esm({
509
- "src/server/entities/user-permissions.ts"() {
510
- "use strict";
511
- init_users();
512
- init_permissions();
513
- init_schema();
514
- userPermissions = authSchema.table(
515
- "user_permissions",
516
- {
517
- // Primary key
518
- id: id9(),
519
- // Foreign key to users table
520
- userId: bigint4("user_id", { mode: "number" }).notNull().references(() => users.id, { onDelete: "cascade" }),
521
- // Foreign key to permissions table
522
- permissionId: bigint4("permission_id", { mode: "number" }).notNull().references(() => permissions.id, { onDelete: "cascade" }),
523
- // Grant or revoke
524
- // true: Grant this permission (even if role doesn't have it)
525
- // false: Revoke this permission (even if role has it)
526
- granted: boolean5("granted").notNull().default(true),
527
- // Reason for grant/revocation (audit trail)
528
- reason: text8("reason"),
529
- // Expiration timestamp (optional)
530
- // null: Permanent override
531
- // timestamp: Permission expires at this time
532
- expiresAt: timestamp6("expires_at", { withTimezone: true }),
533
- ...timestamps8()
534
- },
535
- (table) => [
536
- // Indexes for query performance
537
- index8("user_permissions_user_id_idx").on(table.userId),
538
- index8("user_permissions_permission_id_idx").on(table.permissionId),
539
- index8("user_permissions_expires_at_idx").on(table.expiresAt),
540
- // Unique constraint: one user-permission pair only
541
- unique2("user_permissions_unique").on(table.userId, table.permissionId)
542
- ]
543
- );
544
- }
545
- });
546
-
547
- // src/server/entities/index.ts
548
- var entities_exports = {};
549
- __export(entities_exports, {
550
- authSchema: () => authSchema,
551
- invitations: () => invitations,
552
- permissions: () => permissions,
553
- rolePermissions: () => rolePermissions,
554
- roles: () => roles,
555
- userPermissions: () => userPermissions,
556
- userPublicKeys: () => userPublicKeys,
557
- userSocialAccounts: () => userSocialAccounts,
558
- users: () => users,
559
- verificationCodes: () => verificationCodes
560
- });
561
- var init_entities = __esm({
562
- "src/server/entities/index.ts"() {
563
- "use strict";
564
- init_schema();
565
- init_users();
566
- init_user_social_accounts();
567
- init_user_public_keys();
568
- init_verification_codes();
569
- init_invitations();
570
- init_roles();
571
- init_permissions();
572
- init_role_permissions();
573
- init_user_permissions();
574
- }
575
- });
576
-
577
- // src/server/services/role.service.ts
578
- import { getDatabase as getDatabase7 } from "@spfn/core/db";
579
- import { eq as eq7, and as and7 } from "drizzle-orm";
580
- var init_role_service = __esm({
581
- "src/server/services/role.service.ts"() {
582
- "use strict";
583
- init_entities();
584
- }
585
- });
586
-
587
- // src/server/routes/invitations/index.ts
588
- import { createApp } from "@spfn/core/route";
589
-
590
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/guard/value.mjs
591
- var value_exports = {};
592
- __export(value_exports, {
593
- HasPropertyKey: () => HasPropertyKey,
594
- IsArray: () => IsArray,
595
- IsAsyncIterator: () => IsAsyncIterator,
596
- IsBigInt: () => IsBigInt,
597
- IsBoolean: () => IsBoolean,
598
- IsDate: () => IsDate,
599
- IsFunction: () => IsFunction,
600
- IsIterator: () => IsIterator,
601
- IsNull: () => IsNull,
602
- IsNumber: () => IsNumber,
603
- IsObject: () => IsObject,
604
- IsRegExp: () => IsRegExp,
605
- IsString: () => IsString,
606
- IsSymbol: () => IsSymbol,
607
- IsUint8Array: () => IsUint8Array,
608
- IsUndefined: () => IsUndefined
609
- });
610
- function HasPropertyKey(value, key) {
611
- return key in value;
612
- }
613
- function IsAsyncIterator(value) {
614
- return IsObject(value) && !IsArray(value) && !IsUint8Array(value) && Symbol.asyncIterator in value;
615
- }
616
- function IsArray(value) {
617
- return Array.isArray(value);
618
- }
619
- function IsBigInt(value) {
620
- return typeof value === "bigint";
621
- }
622
- function IsBoolean(value) {
623
- return typeof value === "boolean";
624
- }
625
- function IsDate(value) {
626
- return value instanceof globalThis.Date;
627
- }
628
- function IsFunction(value) {
629
- return typeof value === "function";
630
- }
631
- function IsIterator(value) {
632
- return IsObject(value) && !IsArray(value) && !IsUint8Array(value) && Symbol.iterator in value;
633
- }
634
- function IsNull(value) {
635
- return value === null;
636
- }
637
- function IsNumber(value) {
638
- return typeof value === "number";
639
- }
640
- function IsObject(value) {
641
- return typeof value === "object" && value !== null;
642
- }
643
- function IsRegExp(value) {
644
- return value instanceof globalThis.RegExp;
645
- }
646
- function IsString(value) {
647
- return typeof value === "string";
648
- }
649
- function IsSymbol(value) {
650
- return typeof value === "symbol";
651
- }
652
- function IsUint8Array(value) {
653
- return value instanceof globalThis.Uint8Array;
654
- }
655
- function IsUndefined(value) {
656
- return value === void 0;
657
- }
658
-
659
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/clone/value.mjs
660
- function ArrayType(value) {
661
- return value.map((value2) => Visit(value2));
662
- }
663
- function DateType(value) {
664
- return new Date(value.getTime());
665
- }
666
- function Uint8ArrayType(value) {
667
- return new Uint8Array(value);
668
- }
669
- function RegExpType(value) {
670
- return new RegExp(value.source, value.flags);
671
- }
672
- function ObjectType(value) {
673
- const result = {};
674
- for (const key of Object.getOwnPropertyNames(value)) {
675
- result[key] = Visit(value[key]);
676
- }
677
- for (const key of Object.getOwnPropertySymbols(value)) {
678
- result[key] = Visit(value[key]);
679
- }
680
- return result;
681
- }
682
- function Visit(value) {
683
- return IsArray(value) ? ArrayType(value) : IsDate(value) ? DateType(value) : IsUint8Array(value) ? Uint8ArrayType(value) : IsRegExp(value) ? RegExpType(value) : IsObject(value) ? ObjectType(value) : value;
684
- }
685
- function Clone(value) {
686
- return Visit(value);
687
- }
688
-
689
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/clone/type.mjs
690
- function CloneType(schema, options) {
691
- return options === void 0 ? Clone(schema) : Clone({ ...options, ...schema });
692
- }
693
-
694
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/value/guard/guard.mjs
695
- function IsObject2(value) {
696
- return value !== null && typeof value === "object";
697
- }
698
- function IsArray2(value) {
699
- return globalThis.Array.isArray(value) && !globalThis.ArrayBuffer.isView(value);
700
- }
701
- function IsUndefined2(value) {
702
- return value === void 0;
703
- }
704
- function IsNumber2(value) {
705
- return typeof value === "number";
706
- }
707
-
708
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/system/policy.mjs
709
- var TypeSystemPolicy;
710
- (function(TypeSystemPolicy2) {
711
- TypeSystemPolicy2.InstanceMode = "default";
712
- TypeSystemPolicy2.ExactOptionalPropertyTypes = false;
713
- TypeSystemPolicy2.AllowArrayObject = false;
714
- TypeSystemPolicy2.AllowNaN = false;
715
- TypeSystemPolicy2.AllowNullVoid = false;
716
- function IsExactOptionalProperty(value, key) {
717
- return TypeSystemPolicy2.ExactOptionalPropertyTypes ? key in value : value[key] !== void 0;
718
- }
719
- TypeSystemPolicy2.IsExactOptionalProperty = IsExactOptionalProperty;
720
- function IsObjectLike(value) {
721
- const isObject = IsObject2(value);
722
- return TypeSystemPolicy2.AllowArrayObject ? isObject : isObject && !IsArray2(value);
723
- }
724
- TypeSystemPolicy2.IsObjectLike = IsObjectLike;
725
- function IsRecordLike(value) {
726
- return IsObjectLike(value) && !(value instanceof Date) && !(value instanceof Uint8Array);
727
- }
728
- TypeSystemPolicy2.IsRecordLike = IsRecordLike;
729
- function IsNumberLike(value) {
730
- return TypeSystemPolicy2.AllowNaN ? IsNumber2(value) : Number.isFinite(value);
731
- }
732
- TypeSystemPolicy2.IsNumberLike = IsNumberLike;
733
- function IsVoidLike(value) {
734
- const isUndefined = IsUndefined2(value);
735
- return TypeSystemPolicy2.AllowNullVoid ? isUndefined || value === null : isUndefined;
736
- }
737
- TypeSystemPolicy2.IsVoidLike = IsVoidLike;
738
- })(TypeSystemPolicy || (TypeSystemPolicy = {}));
739
-
740
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/create/immutable.mjs
741
- function ImmutableArray(value) {
742
- return globalThis.Object.freeze(value).map((value2) => Immutable(value2));
743
- }
744
- function ImmutableDate(value) {
745
- return value;
746
- }
747
- function ImmutableUint8Array(value) {
748
- return value;
749
- }
750
- function ImmutableRegExp(value) {
751
- return value;
752
- }
753
- function ImmutableObject(value) {
754
- const result = {};
755
- for (const key of Object.getOwnPropertyNames(value)) {
756
- result[key] = Immutable(value[key]);
757
- }
758
- for (const key of Object.getOwnPropertySymbols(value)) {
759
- result[key] = Immutable(value[key]);
760
- }
761
- return globalThis.Object.freeze(result);
762
- }
763
- function Immutable(value) {
764
- return IsArray(value) ? ImmutableArray(value) : IsDate(value) ? ImmutableDate(value) : IsUint8Array(value) ? ImmutableUint8Array(value) : IsRegExp(value) ? ImmutableRegExp(value) : IsObject(value) ? ImmutableObject(value) : value;
765
- }
766
-
767
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/create/type.mjs
768
- function CreateType(schema, options) {
769
- const result = options !== void 0 ? { ...options, ...schema } : schema;
770
- switch (TypeSystemPolicy.InstanceMode) {
771
- case "freeze":
772
- return Immutable(result);
773
- case "clone":
774
- return Clone(result);
775
- default:
776
- return result;
777
- }
778
- }
779
-
780
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/error/error.mjs
781
- var TypeBoxError = class extends Error {
782
- constructor(message) {
783
- super(message);
784
- }
785
- };
786
-
787
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/symbols/symbols.mjs
788
- var TransformKind = Symbol.for("TypeBox.Transform");
789
- var ReadonlyKind = Symbol.for("TypeBox.Readonly");
790
- var OptionalKind = Symbol.for("TypeBox.Optional");
791
- var Hint = Symbol.for("TypeBox.Hint");
792
- var Kind = Symbol.for("TypeBox.Kind");
793
-
794
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/guard/kind.mjs
795
- function IsReadonly(value) {
796
- return IsObject(value) && value[ReadonlyKind] === "Readonly";
797
- }
798
- function IsOptional(value) {
799
- return IsObject(value) && value[OptionalKind] === "Optional";
800
- }
801
- function IsAny(value) {
802
- return IsKindOf(value, "Any");
803
- }
804
- function IsArgument(value) {
805
- return IsKindOf(value, "Argument");
806
- }
807
- function IsArray3(value) {
808
- return IsKindOf(value, "Array");
809
- }
810
- function IsAsyncIterator2(value) {
811
- return IsKindOf(value, "AsyncIterator");
812
- }
813
- function IsBigInt2(value) {
814
- return IsKindOf(value, "BigInt");
815
- }
816
- function IsBoolean2(value) {
817
- return IsKindOf(value, "Boolean");
818
- }
819
- function IsComputed(value) {
820
- return IsKindOf(value, "Computed");
821
- }
822
- function IsConstructor(value) {
823
- return IsKindOf(value, "Constructor");
824
- }
825
- function IsDate2(value) {
826
- return IsKindOf(value, "Date");
827
- }
828
- function IsFunction2(value) {
829
- return IsKindOf(value, "Function");
830
- }
831
- function IsInteger(value) {
832
- return IsKindOf(value, "Integer");
833
- }
834
- function IsIntersect(value) {
835
- return IsKindOf(value, "Intersect");
836
- }
837
- function IsIterator2(value) {
838
- return IsKindOf(value, "Iterator");
839
- }
840
- function IsKindOf(value, kind) {
841
- return IsObject(value) && Kind in value && value[Kind] === kind;
842
- }
843
- function IsLiteralValue(value) {
844
- return IsBoolean(value) || IsNumber(value) || IsString(value);
845
- }
846
- function IsLiteral(value) {
847
- return IsKindOf(value, "Literal");
848
- }
849
- function IsMappedKey(value) {
850
- return IsKindOf(value, "MappedKey");
851
- }
852
- function IsMappedResult(value) {
853
- return IsKindOf(value, "MappedResult");
854
- }
855
- function IsNever(value) {
856
- return IsKindOf(value, "Never");
857
- }
858
- function IsNot(value) {
859
- return IsKindOf(value, "Not");
860
- }
861
- function IsNull2(value) {
862
- return IsKindOf(value, "Null");
863
- }
864
- function IsNumber3(value) {
865
- return IsKindOf(value, "Number");
866
- }
867
- function IsObject3(value) {
868
- return IsKindOf(value, "Object");
869
- }
870
- function IsPromise(value) {
871
- return IsKindOf(value, "Promise");
872
- }
873
- function IsRecord(value) {
874
- return IsKindOf(value, "Record");
875
- }
876
- function IsRef(value) {
877
- return IsKindOf(value, "Ref");
878
- }
879
- function IsRegExp2(value) {
880
- return IsKindOf(value, "RegExp");
881
- }
882
- function IsString2(value) {
883
- return IsKindOf(value, "String");
884
- }
885
- function IsSymbol2(value) {
886
- return IsKindOf(value, "Symbol");
887
- }
888
- function IsTemplateLiteral(value) {
889
- return IsKindOf(value, "TemplateLiteral");
890
- }
891
- function IsThis(value) {
892
- return IsKindOf(value, "This");
893
- }
894
- function IsTransform(value) {
895
- return IsObject(value) && TransformKind in value;
896
- }
897
- function IsTuple(value) {
898
- return IsKindOf(value, "Tuple");
899
- }
900
- function IsUndefined3(value) {
901
- return IsKindOf(value, "Undefined");
902
- }
903
- function IsUnion(value) {
904
- return IsKindOf(value, "Union");
905
- }
906
- function IsUint8Array2(value) {
907
- return IsKindOf(value, "Uint8Array");
908
- }
909
- function IsUnknown(value) {
910
- return IsKindOf(value, "Unknown");
911
- }
912
- function IsUnsafe(value) {
913
- return IsKindOf(value, "Unsafe");
914
- }
915
- function IsVoid(value) {
916
- return IsKindOf(value, "Void");
917
- }
918
- function IsKind(value) {
919
- return IsObject(value) && Kind in value && IsString(value[Kind]);
920
- }
921
- function IsSchema(value) {
922
- return IsAny(value) || IsArgument(value) || IsArray3(value) || IsBoolean2(value) || IsBigInt2(value) || IsAsyncIterator2(value) || IsComputed(value) || IsConstructor(value) || IsDate2(value) || IsFunction2(value) || IsInteger(value) || IsIntersect(value) || IsIterator2(value) || IsLiteral(value) || IsMappedKey(value) || IsMappedResult(value) || IsNever(value) || IsNot(value) || IsNull2(value) || IsNumber3(value) || IsObject3(value) || IsPromise(value) || IsRecord(value) || IsRef(value) || IsRegExp2(value) || IsString2(value) || IsSymbol2(value) || IsTemplateLiteral(value) || IsThis(value) || IsTuple(value) || IsUndefined3(value) || IsUnion(value) || IsUint8Array2(value) || IsUnknown(value) || IsUnsafe(value) || IsVoid(value) || IsKind(value);
923
- }
924
-
925
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/guard/type.mjs
926
- var type_exports = {};
927
- __export(type_exports, {
928
- IsAny: () => IsAny2,
929
- IsArgument: () => IsArgument2,
930
- IsArray: () => IsArray4,
931
- IsAsyncIterator: () => IsAsyncIterator3,
932
- IsBigInt: () => IsBigInt3,
933
- IsBoolean: () => IsBoolean3,
934
- IsComputed: () => IsComputed2,
935
- IsConstructor: () => IsConstructor2,
936
- IsDate: () => IsDate3,
937
- IsFunction: () => IsFunction3,
938
- IsImport: () => IsImport,
939
- IsInteger: () => IsInteger2,
940
- IsIntersect: () => IsIntersect2,
941
- IsIterator: () => IsIterator3,
942
- IsKind: () => IsKind2,
943
- IsKindOf: () => IsKindOf2,
944
- IsLiteral: () => IsLiteral2,
945
- IsLiteralBoolean: () => IsLiteralBoolean,
946
- IsLiteralNumber: () => IsLiteralNumber,
947
- IsLiteralString: () => IsLiteralString,
948
- IsLiteralValue: () => IsLiteralValue2,
949
- IsMappedKey: () => IsMappedKey2,
950
- IsMappedResult: () => IsMappedResult2,
951
- IsNever: () => IsNever2,
952
- IsNot: () => IsNot2,
953
- IsNull: () => IsNull3,
954
- IsNumber: () => IsNumber4,
955
- IsObject: () => IsObject4,
956
- IsOptional: () => IsOptional2,
957
- IsPromise: () => IsPromise2,
958
- IsProperties: () => IsProperties,
959
- IsReadonly: () => IsReadonly2,
960
- IsRecord: () => IsRecord2,
961
- IsRecursive: () => IsRecursive,
962
- IsRef: () => IsRef2,
963
- IsRegExp: () => IsRegExp3,
964
- IsSchema: () => IsSchema2,
965
- IsString: () => IsString3,
966
- IsSymbol: () => IsSymbol3,
967
- IsTemplateLiteral: () => IsTemplateLiteral2,
968
- IsThis: () => IsThis2,
969
- IsTransform: () => IsTransform2,
970
- IsTuple: () => IsTuple2,
971
- IsUint8Array: () => IsUint8Array3,
972
- IsUndefined: () => IsUndefined4,
973
- IsUnion: () => IsUnion2,
974
- IsUnionLiteral: () => IsUnionLiteral,
975
- IsUnknown: () => IsUnknown2,
976
- IsUnsafe: () => IsUnsafe2,
977
- IsVoid: () => IsVoid2,
978
- TypeGuardUnknownTypeError: () => TypeGuardUnknownTypeError
979
- });
980
- var TypeGuardUnknownTypeError = class extends TypeBoxError {
981
- };
982
- var KnownTypes = [
983
- "Argument",
984
- "Any",
985
- "Array",
986
- "AsyncIterator",
987
- "BigInt",
988
- "Boolean",
989
- "Computed",
990
- "Constructor",
991
- "Date",
992
- "Enum",
993
- "Function",
994
- "Integer",
995
- "Intersect",
996
- "Iterator",
997
- "Literal",
998
- "MappedKey",
999
- "MappedResult",
1000
- "Not",
1001
- "Null",
1002
- "Number",
1003
- "Object",
1004
- "Promise",
1005
- "Record",
1006
- "Ref",
1007
- "RegExp",
1008
- "String",
1009
- "Symbol",
1010
- "TemplateLiteral",
1011
- "This",
1012
- "Tuple",
1013
- "Undefined",
1014
- "Union",
1015
- "Uint8Array",
1016
- "Unknown",
1017
- "Void"
1018
- ];
1019
- function IsPattern(value) {
1020
- try {
1021
- new RegExp(value);
1022
- return true;
1023
- } catch {
1024
- return false;
1025
- }
1026
- }
1027
- function IsControlCharacterFree(value) {
1028
- if (!IsString(value))
1029
- return false;
1030
- for (let i = 0; i < value.length; i++) {
1031
- const code = value.charCodeAt(i);
1032
- if (code >= 7 && code <= 13 || code === 27 || code === 127) {
1033
- return false;
1034
- }
1035
- }
1036
- return true;
1037
- }
1038
- function IsAdditionalProperties(value) {
1039
- return IsOptionalBoolean(value) || IsSchema2(value);
1040
- }
1041
- function IsOptionalBigInt(value) {
1042
- return IsUndefined(value) || IsBigInt(value);
1043
- }
1044
- function IsOptionalNumber(value) {
1045
- return IsUndefined(value) || IsNumber(value);
1046
- }
1047
- function IsOptionalBoolean(value) {
1048
- return IsUndefined(value) || IsBoolean(value);
1049
- }
1050
- function IsOptionalString(value) {
1051
- return IsUndefined(value) || IsString(value);
1052
- }
1053
- function IsOptionalPattern(value) {
1054
- return IsUndefined(value) || IsString(value) && IsControlCharacterFree(value) && IsPattern(value);
1055
- }
1056
- function IsOptionalFormat(value) {
1057
- return IsUndefined(value) || IsString(value) && IsControlCharacterFree(value);
1058
- }
1059
- function IsOptionalSchema(value) {
1060
- return IsUndefined(value) || IsSchema2(value);
1061
- }
1062
- function IsReadonly2(value) {
1063
- return IsObject(value) && value[ReadonlyKind] === "Readonly";
1064
- }
1065
- function IsOptional2(value) {
1066
- return IsObject(value) && value[OptionalKind] === "Optional";
1067
- }
1068
- function IsAny2(value) {
1069
- return IsKindOf2(value, "Any") && IsOptionalString(value.$id);
1070
- }
1071
- function IsArgument2(value) {
1072
- return IsKindOf2(value, "Argument") && IsNumber(value.index);
1073
- }
1074
- function IsArray4(value) {
1075
- return IsKindOf2(value, "Array") && value.type === "array" && IsOptionalString(value.$id) && IsSchema2(value.items) && IsOptionalNumber(value.minItems) && IsOptionalNumber(value.maxItems) && IsOptionalBoolean(value.uniqueItems) && IsOptionalSchema(value.contains) && IsOptionalNumber(value.minContains) && IsOptionalNumber(value.maxContains);
1076
- }
1077
- function IsAsyncIterator3(value) {
1078
- return IsKindOf2(value, "AsyncIterator") && value.type === "AsyncIterator" && IsOptionalString(value.$id) && IsSchema2(value.items);
1079
- }
1080
- function IsBigInt3(value) {
1081
- return IsKindOf2(value, "BigInt") && value.type === "bigint" && IsOptionalString(value.$id) && IsOptionalBigInt(value.exclusiveMaximum) && IsOptionalBigInt(value.exclusiveMinimum) && IsOptionalBigInt(value.maximum) && IsOptionalBigInt(value.minimum) && IsOptionalBigInt(value.multipleOf);
1082
- }
1083
- function IsBoolean3(value) {
1084
- return IsKindOf2(value, "Boolean") && value.type === "boolean" && IsOptionalString(value.$id);
1085
- }
1086
- function IsComputed2(value) {
1087
- return IsKindOf2(value, "Computed") && IsString(value.target) && IsArray(value.parameters) && value.parameters.every((schema) => IsSchema2(schema));
1088
- }
1089
- function IsConstructor2(value) {
1090
- return IsKindOf2(value, "Constructor") && value.type === "Constructor" && IsOptionalString(value.$id) && IsArray(value.parameters) && value.parameters.every((schema) => IsSchema2(schema)) && IsSchema2(value.returns);
1091
- }
1092
- function IsDate3(value) {
1093
- return IsKindOf2(value, "Date") && value.type === "Date" && IsOptionalString(value.$id) && IsOptionalNumber(value.exclusiveMaximumTimestamp) && IsOptionalNumber(value.exclusiveMinimumTimestamp) && IsOptionalNumber(value.maximumTimestamp) && IsOptionalNumber(value.minimumTimestamp) && IsOptionalNumber(value.multipleOfTimestamp);
1094
- }
1095
- function IsFunction3(value) {
1096
- return IsKindOf2(value, "Function") && value.type === "Function" && IsOptionalString(value.$id) && IsArray(value.parameters) && value.parameters.every((schema) => IsSchema2(schema)) && IsSchema2(value.returns);
1097
- }
1098
- function IsImport(value) {
1099
- return IsKindOf2(value, "Import") && HasPropertyKey(value, "$defs") && IsObject(value.$defs) && IsProperties(value.$defs) && HasPropertyKey(value, "$ref") && IsString(value.$ref) && value.$ref in value.$defs;
1100
- }
1101
- function IsInteger2(value) {
1102
- return IsKindOf2(value, "Integer") && value.type === "integer" && IsOptionalString(value.$id) && IsOptionalNumber(value.exclusiveMaximum) && IsOptionalNumber(value.exclusiveMinimum) && IsOptionalNumber(value.maximum) && IsOptionalNumber(value.minimum) && IsOptionalNumber(value.multipleOf);
1103
- }
1104
- function IsProperties(value) {
1105
- return IsObject(value) && Object.entries(value).every(([key, schema]) => IsControlCharacterFree(key) && IsSchema2(schema));
1106
- }
1107
- function IsIntersect2(value) {
1108
- return IsKindOf2(value, "Intersect") && (IsString(value.type) && value.type !== "object" ? false : true) && IsArray(value.allOf) && value.allOf.every((schema) => IsSchema2(schema) && !IsTransform2(schema)) && IsOptionalString(value.type) && (IsOptionalBoolean(value.unevaluatedProperties) || IsOptionalSchema(value.unevaluatedProperties)) && IsOptionalString(value.$id);
1109
- }
1110
- function IsIterator3(value) {
1111
- return IsKindOf2(value, "Iterator") && value.type === "Iterator" && IsOptionalString(value.$id) && IsSchema2(value.items);
1112
- }
1113
- function IsKindOf2(value, kind) {
1114
- return IsObject(value) && Kind in value && value[Kind] === kind;
1115
- }
1116
- function IsLiteralString(value) {
1117
- return IsLiteral2(value) && IsString(value.const);
1118
- }
1119
- function IsLiteralNumber(value) {
1120
- return IsLiteral2(value) && IsNumber(value.const);
1121
- }
1122
- function IsLiteralBoolean(value) {
1123
- return IsLiteral2(value) && IsBoolean(value.const);
1124
- }
1125
- function IsLiteral2(value) {
1126
- return IsKindOf2(value, "Literal") && IsOptionalString(value.$id) && IsLiteralValue2(value.const);
1127
- }
1128
- function IsLiteralValue2(value) {
1129
- return IsBoolean(value) || IsNumber(value) || IsString(value);
1130
- }
1131
- function IsMappedKey2(value) {
1132
- return IsKindOf2(value, "MappedKey") && IsArray(value.keys) && value.keys.every((key) => IsNumber(key) || IsString(key));
1133
- }
1134
- function IsMappedResult2(value) {
1135
- return IsKindOf2(value, "MappedResult") && IsProperties(value.properties);
1136
- }
1137
- function IsNever2(value) {
1138
- return IsKindOf2(value, "Never") && IsObject(value.not) && Object.getOwnPropertyNames(value.not).length === 0;
1139
- }
1140
- function IsNot2(value) {
1141
- return IsKindOf2(value, "Not") && IsSchema2(value.not);
1142
- }
1143
- function IsNull3(value) {
1144
- return IsKindOf2(value, "Null") && value.type === "null" && IsOptionalString(value.$id);
1145
- }
1146
- function IsNumber4(value) {
1147
- return IsKindOf2(value, "Number") && value.type === "number" && IsOptionalString(value.$id) && IsOptionalNumber(value.exclusiveMaximum) && IsOptionalNumber(value.exclusiveMinimum) && IsOptionalNumber(value.maximum) && IsOptionalNumber(value.minimum) && IsOptionalNumber(value.multipleOf);
1148
- }
1149
- function IsObject4(value) {
1150
- return IsKindOf2(value, "Object") && value.type === "object" && IsOptionalString(value.$id) && IsProperties(value.properties) && IsAdditionalProperties(value.additionalProperties) && IsOptionalNumber(value.minProperties) && IsOptionalNumber(value.maxProperties);
1151
- }
1152
- function IsPromise2(value) {
1153
- return IsKindOf2(value, "Promise") && value.type === "Promise" && IsOptionalString(value.$id) && IsSchema2(value.item);
1154
- }
1155
- function IsRecord2(value) {
1156
- return IsKindOf2(value, "Record") && value.type === "object" && IsOptionalString(value.$id) && IsAdditionalProperties(value.additionalProperties) && IsObject(value.patternProperties) && ((schema) => {
1157
- const keys = Object.getOwnPropertyNames(schema.patternProperties);
1158
- return keys.length === 1 && IsPattern(keys[0]) && IsObject(schema.patternProperties) && IsSchema2(schema.patternProperties[keys[0]]);
1159
- })(value);
1160
- }
1161
- function IsRecursive(value) {
1162
- return IsObject(value) && Hint in value && value[Hint] === "Recursive";
1163
- }
1164
- function IsRef2(value) {
1165
- return IsKindOf2(value, "Ref") && IsOptionalString(value.$id) && IsString(value.$ref);
1166
- }
1167
- function IsRegExp3(value) {
1168
- return IsKindOf2(value, "RegExp") && IsOptionalString(value.$id) && IsString(value.source) && IsString(value.flags) && IsOptionalNumber(value.maxLength) && IsOptionalNumber(value.minLength);
1169
- }
1170
- function IsString3(value) {
1171
- return IsKindOf2(value, "String") && value.type === "string" && IsOptionalString(value.$id) && IsOptionalNumber(value.minLength) && IsOptionalNumber(value.maxLength) && IsOptionalPattern(value.pattern) && IsOptionalFormat(value.format);
1172
- }
1173
- function IsSymbol3(value) {
1174
- return IsKindOf2(value, "Symbol") && value.type === "symbol" && IsOptionalString(value.$id);
1175
- }
1176
- function IsTemplateLiteral2(value) {
1177
- return IsKindOf2(value, "TemplateLiteral") && value.type === "string" && IsString(value.pattern) && value.pattern[0] === "^" && value.pattern[value.pattern.length - 1] === "$";
1178
- }
1179
- function IsThis2(value) {
1180
- return IsKindOf2(value, "This") && IsOptionalString(value.$id) && IsString(value.$ref);
1181
- }
1182
- function IsTransform2(value) {
1183
- return IsObject(value) && TransformKind in value;
1184
- }
1185
- function IsTuple2(value) {
1186
- return IsKindOf2(value, "Tuple") && value.type === "array" && IsOptionalString(value.$id) && IsNumber(value.minItems) && IsNumber(value.maxItems) && value.minItems === value.maxItems && // empty
1187
- (IsUndefined(value.items) && IsUndefined(value.additionalItems) && value.minItems === 0 || IsArray(value.items) && value.items.every((schema) => IsSchema2(schema)));
1188
- }
1189
- function IsUndefined4(value) {
1190
- return IsKindOf2(value, "Undefined") && value.type === "undefined" && IsOptionalString(value.$id);
1191
- }
1192
- function IsUnionLiteral(value) {
1193
- return IsUnion2(value) && value.anyOf.every((schema) => IsLiteralString(schema) || IsLiteralNumber(schema));
1194
- }
1195
- function IsUnion2(value) {
1196
- return IsKindOf2(value, "Union") && IsOptionalString(value.$id) && IsObject(value) && IsArray(value.anyOf) && value.anyOf.every((schema) => IsSchema2(schema));
1197
- }
1198
- function IsUint8Array3(value) {
1199
- return IsKindOf2(value, "Uint8Array") && value.type === "Uint8Array" && IsOptionalString(value.$id) && IsOptionalNumber(value.minByteLength) && IsOptionalNumber(value.maxByteLength);
1200
- }
1201
- function IsUnknown2(value) {
1202
- return IsKindOf2(value, "Unknown") && IsOptionalString(value.$id);
1203
- }
1204
- function IsUnsafe2(value) {
1205
- return IsKindOf2(value, "Unsafe");
1206
- }
1207
- function IsVoid2(value) {
1208
- return IsKindOf2(value, "Void") && value.type === "void" && IsOptionalString(value.$id);
1209
- }
1210
- function IsKind2(value) {
1211
- return IsObject(value) && Kind in value && IsString(value[Kind]) && !KnownTypes.includes(value[Kind]);
1212
- }
1213
- function IsSchema2(value) {
1214
- return IsObject(value) && (IsAny2(value) || IsArgument2(value) || IsArray4(value) || IsBoolean3(value) || IsBigInt3(value) || IsAsyncIterator3(value) || IsComputed2(value) || IsConstructor2(value) || IsDate3(value) || IsFunction3(value) || IsInteger2(value) || IsIntersect2(value) || IsIterator3(value) || IsLiteral2(value) || IsMappedKey2(value) || IsMappedResult2(value) || IsNever2(value) || IsNot2(value) || IsNull3(value) || IsNumber4(value) || IsObject4(value) || IsPromise2(value) || IsRecord2(value) || IsRef2(value) || IsRegExp3(value) || IsString3(value) || IsSymbol3(value) || IsTemplateLiteral2(value) || IsThis2(value) || IsTuple2(value) || IsUndefined4(value) || IsUnion2(value) || IsUint8Array3(value) || IsUnknown2(value) || IsUnsafe2(value) || IsVoid2(value) || IsKind2(value));
1215
- }
1216
-
1217
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/patterns/patterns.mjs
1218
- var PatternBoolean = "(true|false)";
1219
- var PatternNumber = "(0|[1-9][0-9]*)";
1220
- var PatternString = "(.*)";
1221
- var PatternNever = "(?!.*)";
1222
- var PatternBooleanExact = `^${PatternBoolean}$`;
1223
- var PatternNumberExact = `^${PatternNumber}$`;
1224
- var PatternStringExact = `^${PatternString}$`;
1225
- var PatternNeverExact = `^${PatternNever}$`;
1226
-
1227
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/sets/set.mjs
1228
- function SetIncludes(T, S) {
1229
- return T.includes(S);
1230
- }
1231
- function SetDistinct(T) {
1232
- return [...new Set(T)];
1233
- }
1234
- function SetIntersect(T, S) {
1235
- return T.filter((L) => S.includes(L));
1236
- }
1237
- function SetIntersectManyResolve(T, Init) {
1238
- return T.reduce((Acc, L) => {
1239
- return SetIntersect(Acc, L);
1240
- }, Init);
1241
- }
1242
- function SetIntersectMany(T) {
1243
- return T.length === 1 ? T[0] : T.length > 1 ? SetIntersectManyResolve(T.slice(1), T[0]) : [];
1244
- }
1245
- function SetUnionMany(T) {
1246
- const Acc = [];
1247
- for (const L of T)
1248
- Acc.push(...L);
1249
- return Acc;
1250
- }
1251
-
1252
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/any/any.mjs
1253
- function Any(options) {
1254
- return CreateType({ [Kind]: "Any" }, options);
1255
- }
1256
-
1257
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/array/array.mjs
1258
- function Array2(items, options) {
1259
- return CreateType({ [Kind]: "Array", type: "array", items }, options);
1260
- }
1261
-
1262
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/argument/argument.mjs
1263
- function Argument(index9) {
1264
- return CreateType({ [Kind]: "Argument", index: index9 });
1265
- }
1266
-
1267
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/async-iterator/async-iterator.mjs
1268
- function AsyncIterator(items, options) {
1269
- return CreateType({ [Kind]: "AsyncIterator", type: "AsyncIterator", items }, options);
1270
- }
1271
-
1272
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/computed/computed.mjs
1273
- function Computed(target, parameters, options) {
1274
- return CreateType({ [Kind]: "Computed", target, parameters }, options);
1275
- }
1276
-
1277
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/discard/discard.mjs
1278
- function DiscardKey(value, key) {
1279
- const { [key]: _, ...rest } = value;
1280
- return rest;
1281
- }
1282
- function Discard(value, keys) {
1283
- return keys.reduce((acc, key) => DiscardKey(acc, key), value);
1284
- }
1285
-
1286
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/never/never.mjs
1287
- function Never(options) {
1288
- return CreateType({ [Kind]: "Never", not: {} }, options);
1289
- }
1290
-
1291
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/mapped/mapped-result.mjs
1292
- function MappedResult(properties) {
1293
- return CreateType({
1294
- [Kind]: "MappedResult",
1295
- properties
1296
- });
1297
- }
1298
-
1299
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/constructor/constructor.mjs
1300
- function Constructor(parameters, returns, options) {
1301
- return CreateType({ [Kind]: "Constructor", type: "Constructor", parameters, returns }, options);
1302
- }
1303
-
1304
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/function/function.mjs
1305
- function Function(parameters, returns, options) {
1306
- return CreateType({ [Kind]: "Function", type: "Function", parameters, returns }, options);
1307
- }
1308
-
1309
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/union/union-create.mjs
1310
- function UnionCreate(T, options) {
1311
- return CreateType({ [Kind]: "Union", anyOf: T }, options);
1312
- }
1313
-
1314
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/union/union-evaluated.mjs
1315
- function IsUnionOptional(types) {
1316
- return types.some((type) => IsOptional(type));
1317
- }
1318
- function RemoveOptionalFromRest(types) {
1319
- return types.map((left) => IsOptional(left) ? RemoveOptionalFromType(left) : left);
1320
- }
1321
- function RemoveOptionalFromType(T) {
1322
- return Discard(T, [OptionalKind]);
1323
- }
1324
- function ResolveUnion(types, options) {
1325
- const isOptional = IsUnionOptional(types);
1326
- return isOptional ? Optional(UnionCreate(RemoveOptionalFromRest(types), options)) : UnionCreate(RemoveOptionalFromRest(types), options);
1327
- }
1328
- function UnionEvaluated(T, options) {
1329
- return T.length === 1 ? CreateType(T[0], options) : T.length === 0 ? Never(options) : ResolveUnion(T, options);
1330
- }
1331
-
1332
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/union/union.mjs
1333
- function Union(types, options) {
1334
- return types.length === 0 ? Never(options) : types.length === 1 ? CreateType(types[0], options) : UnionCreate(types, options);
1335
- }
1336
-
1337
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/template-literal/parse.mjs
1338
- var TemplateLiteralParserError = class extends TypeBoxError {
1339
- };
1340
- function Unescape(pattern) {
1341
- return pattern.replace(/\\\$/g, "$").replace(/\\\*/g, "*").replace(/\\\^/g, "^").replace(/\\\|/g, "|").replace(/\\\(/g, "(").replace(/\\\)/g, ")");
1342
- }
1343
- function IsNonEscaped(pattern, index9, char) {
1344
- return pattern[index9] === char && pattern.charCodeAt(index9 - 1) !== 92;
1345
- }
1346
- function IsOpenParen(pattern, index9) {
1347
- return IsNonEscaped(pattern, index9, "(");
1348
- }
1349
- function IsCloseParen(pattern, index9) {
1350
- return IsNonEscaped(pattern, index9, ")");
1351
- }
1352
- function IsSeparator(pattern, index9) {
1353
- return IsNonEscaped(pattern, index9, "|");
1354
- }
1355
- function IsGroup(pattern) {
1356
- if (!(IsOpenParen(pattern, 0) && IsCloseParen(pattern, pattern.length - 1)))
1357
- return false;
1358
- let count = 0;
1359
- for (let index9 = 0; index9 < pattern.length; index9++) {
1360
- if (IsOpenParen(pattern, index9))
1361
- count += 1;
1362
- if (IsCloseParen(pattern, index9))
1363
- count -= 1;
1364
- if (count === 0 && index9 !== pattern.length - 1)
1365
- return false;
1366
- }
1367
- return true;
1368
- }
1369
- function InGroup(pattern) {
1370
- return pattern.slice(1, pattern.length - 1);
1371
- }
1372
- function IsPrecedenceOr(pattern) {
1373
- let count = 0;
1374
- for (let index9 = 0; index9 < pattern.length; index9++) {
1375
- if (IsOpenParen(pattern, index9))
1376
- count += 1;
1377
- if (IsCloseParen(pattern, index9))
1378
- count -= 1;
1379
- if (IsSeparator(pattern, index9) && count === 0)
1380
- return true;
1381
- }
1382
- return false;
1383
- }
1384
- function IsPrecedenceAnd(pattern) {
1385
- for (let index9 = 0; index9 < pattern.length; index9++) {
1386
- if (IsOpenParen(pattern, index9))
1387
- return true;
1388
- }
1389
- return false;
1390
- }
1391
- function Or(pattern) {
1392
- let [count, start] = [0, 0];
1393
- const expressions = [];
1394
- for (let index9 = 0; index9 < pattern.length; index9++) {
1395
- if (IsOpenParen(pattern, index9))
1396
- count += 1;
1397
- if (IsCloseParen(pattern, index9))
1398
- count -= 1;
1399
- if (IsSeparator(pattern, index9) && count === 0) {
1400
- const range2 = pattern.slice(start, index9);
1401
- if (range2.length > 0)
1402
- expressions.push(TemplateLiteralParse(range2));
1403
- start = index9 + 1;
1404
- }
1405
- }
1406
- const range = pattern.slice(start);
1407
- if (range.length > 0)
1408
- expressions.push(TemplateLiteralParse(range));
1409
- if (expressions.length === 0)
1410
- return { type: "const", const: "" };
1411
- if (expressions.length === 1)
1412
- return expressions[0];
1413
- return { type: "or", expr: expressions };
1414
- }
1415
- function And(pattern) {
1416
- function Group(value, index9) {
1417
- if (!IsOpenParen(value, index9))
1418
- throw new TemplateLiteralParserError(`TemplateLiteralParser: Index must point to open parens`);
1419
- let count = 0;
1420
- for (let scan = index9; scan < value.length; scan++) {
1421
- if (IsOpenParen(value, scan))
1422
- count += 1;
1423
- if (IsCloseParen(value, scan))
1424
- count -= 1;
1425
- if (count === 0)
1426
- return [index9, scan];
1427
- }
1428
- throw new TemplateLiteralParserError(`TemplateLiteralParser: Unclosed group parens in expression`);
1429
- }
1430
- function Range(pattern2, index9) {
1431
- for (let scan = index9; scan < pattern2.length; scan++) {
1432
- if (IsOpenParen(pattern2, scan))
1433
- return [index9, scan];
1434
- }
1435
- return [index9, pattern2.length];
1436
- }
1437
- const expressions = [];
1438
- for (let index9 = 0; index9 < pattern.length; index9++) {
1439
- if (IsOpenParen(pattern, index9)) {
1440
- const [start, end] = Group(pattern, index9);
1441
- const range = pattern.slice(start, end + 1);
1442
- expressions.push(TemplateLiteralParse(range));
1443
- index9 = end;
1444
- } else {
1445
- const [start, end] = Range(pattern, index9);
1446
- const range = pattern.slice(start, end);
1447
- if (range.length > 0)
1448
- expressions.push(TemplateLiteralParse(range));
1449
- index9 = end - 1;
1450
- }
1451
- }
1452
- return expressions.length === 0 ? { type: "const", const: "" } : expressions.length === 1 ? expressions[0] : { type: "and", expr: expressions };
1453
- }
1454
- function TemplateLiteralParse(pattern) {
1455
- return IsGroup(pattern) ? TemplateLiteralParse(InGroup(pattern)) : IsPrecedenceOr(pattern) ? Or(pattern) : IsPrecedenceAnd(pattern) ? And(pattern) : { type: "const", const: Unescape(pattern) };
1456
- }
1457
- function TemplateLiteralParseExact(pattern) {
1458
- return TemplateLiteralParse(pattern.slice(1, pattern.length - 1));
1459
- }
1460
-
1461
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/template-literal/finite.mjs
1462
- var TemplateLiteralFiniteError = class extends TypeBoxError {
1463
- };
1464
- function IsNumberExpression(expression) {
1465
- return expression.type === "or" && expression.expr.length === 2 && expression.expr[0].type === "const" && expression.expr[0].const === "0" && expression.expr[1].type === "const" && expression.expr[1].const === "[1-9][0-9]*";
1466
- }
1467
- function IsBooleanExpression(expression) {
1468
- return expression.type === "or" && expression.expr.length === 2 && expression.expr[0].type === "const" && expression.expr[0].const === "true" && expression.expr[1].type === "const" && expression.expr[1].const === "false";
1469
- }
1470
- function IsStringExpression(expression) {
1471
- return expression.type === "const" && expression.const === ".*";
1472
- }
1473
- function IsTemplateLiteralExpressionFinite(expression) {
1474
- return IsNumberExpression(expression) || IsStringExpression(expression) ? false : IsBooleanExpression(expression) ? true : expression.type === "and" ? expression.expr.every((expr) => IsTemplateLiteralExpressionFinite(expr)) : expression.type === "or" ? expression.expr.every((expr) => IsTemplateLiteralExpressionFinite(expr)) : expression.type === "const" ? true : (() => {
1475
- throw new TemplateLiteralFiniteError(`Unknown expression type`);
1476
- })();
1477
- }
1478
- function IsTemplateLiteralFinite(schema) {
1479
- const expression = TemplateLiteralParseExact(schema.pattern);
1480
- return IsTemplateLiteralExpressionFinite(expression);
1481
- }
1482
-
1483
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/template-literal/generate.mjs
1484
- var TemplateLiteralGenerateError = class extends TypeBoxError {
1485
- };
1486
- function* GenerateReduce(buffer) {
1487
- if (buffer.length === 1)
1488
- return yield* buffer[0];
1489
- for (const left of buffer[0]) {
1490
- for (const right of GenerateReduce(buffer.slice(1))) {
1491
- yield `${left}${right}`;
1492
- }
1493
- }
1494
- }
1495
- function* GenerateAnd(expression) {
1496
- return yield* GenerateReduce(expression.expr.map((expr) => [...TemplateLiteralExpressionGenerate(expr)]));
1497
- }
1498
- function* GenerateOr(expression) {
1499
- for (const expr of expression.expr)
1500
- yield* TemplateLiteralExpressionGenerate(expr);
1501
- }
1502
- function* GenerateConst(expression) {
1503
- return yield expression.const;
1504
- }
1505
- function* TemplateLiteralExpressionGenerate(expression) {
1506
- return expression.type === "and" ? yield* GenerateAnd(expression) : expression.type === "or" ? yield* GenerateOr(expression) : expression.type === "const" ? yield* GenerateConst(expression) : (() => {
1507
- throw new TemplateLiteralGenerateError("Unknown expression");
1508
- })();
1509
- }
1510
- function TemplateLiteralGenerate(schema) {
1511
- const expression = TemplateLiteralParseExact(schema.pattern);
1512
- return IsTemplateLiteralExpressionFinite(expression) ? [...TemplateLiteralExpressionGenerate(expression)] : [];
1513
- }
1514
-
1515
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/literal/literal.mjs
1516
- function Literal(value, options) {
1517
- return CreateType({
1518
- [Kind]: "Literal",
1519
- const: value,
1520
- type: typeof value
1521
- }, options);
1522
- }
1523
-
1524
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/boolean/boolean.mjs
1525
- function Boolean(options) {
1526
- return CreateType({ [Kind]: "Boolean", type: "boolean" }, options);
1527
- }
1528
-
1529
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/bigint/bigint.mjs
1530
- function BigInt(options) {
1531
- return CreateType({ [Kind]: "BigInt", type: "bigint" }, options);
1532
- }
1533
-
1534
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/number/number.mjs
1535
- function Number2(options) {
1536
- return CreateType({ [Kind]: "Number", type: "number" }, options);
1537
- }
1538
-
1539
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/string/string.mjs
1540
- function String2(options) {
1541
- return CreateType({ [Kind]: "String", type: "string" }, options);
1542
- }
1543
-
1544
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/template-literal/syntax.mjs
1545
- function* FromUnion(syntax) {
1546
- const trim = syntax.trim().replace(/"|'/g, "");
1547
- return trim === "boolean" ? yield Boolean() : trim === "number" ? yield Number2() : trim === "bigint" ? yield BigInt() : trim === "string" ? yield String2() : yield (() => {
1548
- const literals = trim.split("|").map((literal) => Literal(literal.trim()));
1549
- return literals.length === 0 ? Never() : literals.length === 1 ? literals[0] : UnionEvaluated(literals);
1550
- })();
1551
- }
1552
- function* FromTerminal(syntax) {
1553
- if (syntax[1] !== "{") {
1554
- const L = Literal("$");
1555
- const R = FromSyntax(syntax.slice(1));
1556
- return yield* [L, ...R];
1557
- }
1558
- for (let i = 2; i < syntax.length; i++) {
1559
- if (syntax[i] === "}") {
1560
- const L = FromUnion(syntax.slice(2, i));
1561
- const R = FromSyntax(syntax.slice(i + 1));
1562
- return yield* [...L, ...R];
1563
- }
1564
- }
1565
- yield Literal(syntax);
1566
- }
1567
- function* FromSyntax(syntax) {
1568
- for (let i = 0; i < syntax.length; i++) {
1569
- if (syntax[i] === "$") {
1570
- const L = Literal(syntax.slice(0, i));
1571
- const R = FromTerminal(syntax.slice(i));
1572
- return yield* [L, ...R];
1573
- }
1574
- }
1575
- yield Literal(syntax);
1576
- }
1577
- function TemplateLiteralSyntax(syntax) {
1578
- return [...FromSyntax(syntax)];
1579
- }
1580
-
1581
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/template-literal/pattern.mjs
1582
- var TemplateLiteralPatternError = class extends TypeBoxError {
1583
- };
1584
- function Escape(value) {
1585
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1586
- }
1587
- function Visit2(schema, acc) {
1588
- return IsTemplateLiteral(schema) ? schema.pattern.slice(1, schema.pattern.length - 1) : IsUnion(schema) ? `(${schema.anyOf.map((schema2) => Visit2(schema2, acc)).join("|")})` : IsNumber3(schema) ? `${acc}${PatternNumber}` : IsInteger(schema) ? `${acc}${PatternNumber}` : IsBigInt2(schema) ? `${acc}${PatternNumber}` : IsString2(schema) ? `${acc}${PatternString}` : IsLiteral(schema) ? `${acc}${Escape(schema.const.toString())}` : IsBoolean2(schema) ? `${acc}${PatternBoolean}` : (() => {
1589
- throw new TemplateLiteralPatternError(`Unexpected Kind '${schema[Kind]}'`);
1590
- })();
1591
- }
1592
- function TemplateLiteralPattern(kinds) {
1593
- return `^${kinds.map((schema) => Visit2(schema, "")).join("")}$`;
1594
- }
1595
-
1596
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/template-literal/union.mjs
1597
- function TemplateLiteralToUnion(schema) {
1598
- const R = TemplateLiteralGenerate(schema);
1599
- const L = R.map((S) => Literal(S));
1600
- return UnionEvaluated(L);
1601
- }
1602
-
1603
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/template-literal/template-literal.mjs
1604
- function TemplateLiteral(unresolved, options) {
1605
- const pattern = IsString(unresolved) ? TemplateLiteralPattern(TemplateLiteralSyntax(unresolved)) : TemplateLiteralPattern(unresolved);
1606
- return CreateType({ [Kind]: "TemplateLiteral", type: "string", pattern }, options);
1607
- }
1608
-
1609
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/indexed/indexed-property-keys.mjs
1610
- function FromTemplateLiteral(templateLiteral) {
1611
- const keys = TemplateLiteralGenerate(templateLiteral);
1612
- return keys.map((key) => key.toString());
1613
- }
1614
- function FromUnion2(types) {
1615
- const result = [];
1616
- for (const type of types)
1617
- result.push(...IndexPropertyKeys(type));
1618
- return result;
1619
- }
1620
- function FromLiteral(literalValue) {
1621
- return [literalValue.toString()];
1622
- }
1623
- function IndexPropertyKeys(type) {
1624
- return [...new Set(IsTemplateLiteral(type) ? FromTemplateLiteral(type) : IsUnion(type) ? FromUnion2(type.anyOf) : IsLiteral(type) ? FromLiteral(type.const) : IsNumber3(type) ? ["[number]"] : IsInteger(type) ? ["[number]"] : [])];
1625
- }
1626
-
1627
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/indexed/indexed-from-mapped-result.mjs
1628
- function FromProperties(type, properties, options) {
1629
- const result = {};
1630
- for (const K2 of Object.getOwnPropertyNames(properties)) {
1631
- result[K2] = Index(type, IndexPropertyKeys(properties[K2]), options);
1632
- }
1633
- return result;
1634
- }
1635
- function FromMappedResult(type, mappedResult, options) {
1636
- return FromProperties(type, mappedResult.properties, options);
1637
- }
1638
- function IndexFromMappedResult(type, mappedResult, options) {
1639
- const properties = FromMappedResult(type, mappedResult, options);
1640
- return MappedResult(properties);
1641
- }
1642
-
1643
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/indexed/indexed.mjs
1644
- function FromRest(types, key) {
1645
- return types.map((type) => IndexFromPropertyKey(type, key));
1646
- }
1647
- function FromIntersectRest(types) {
1648
- return types.filter((type) => !IsNever(type));
1649
- }
1650
- function FromIntersect(types, key) {
1651
- return IntersectEvaluated(FromIntersectRest(FromRest(types, key)));
1652
- }
1653
- function FromUnionRest(types) {
1654
- return types.some((L) => IsNever(L)) ? [] : types;
1655
- }
1656
- function FromUnion3(types, key) {
1657
- return UnionEvaluated(FromUnionRest(FromRest(types, key)));
1658
- }
1659
- function FromTuple(types, key) {
1660
- return key in types ? types[key] : key === "[number]" ? UnionEvaluated(types) : Never();
1661
- }
1662
- function FromArray(type, key) {
1663
- return key === "[number]" ? type : Never();
1664
- }
1665
- function FromProperty(properties, propertyKey) {
1666
- return propertyKey in properties ? properties[propertyKey] : Never();
1667
- }
1668
- function IndexFromPropertyKey(type, propertyKey) {
1669
- return IsIntersect(type) ? FromIntersect(type.allOf, propertyKey) : IsUnion(type) ? FromUnion3(type.anyOf, propertyKey) : IsTuple(type) ? FromTuple(type.items ?? [], propertyKey) : IsArray3(type) ? FromArray(type.items, propertyKey) : IsObject3(type) ? FromProperty(type.properties, propertyKey) : Never();
1670
- }
1671
- function IndexFromPropertyKeys(type, propertyKeys) {
1672
- return propertyKeys.map((propertyKey) => IndexFromPropertyKey(type, propertyKey));
1673
- }
1674
- function FromSchema(type, propertyKeys) {
1675
- return UnionEvaluated(IndexFromPropertyKeys(type, propertyKeys));
1676
- }
1677
- function Index(type, key, options) {
1678
- if (IsRef(type) || IsRef(key)) {
1679
- const error = `Index types using Ref parameters require both Type and Key to be of TSchema`;
1680
- if (!IsSchema(type) || !IsSchema(key))
1681
- throw new TypeBoxError(error);
1682
- return Computed("Index", [type, key]);
1683
- }
1684
- if (IsMappedResult(key))
1685
- return IndexFromMappedResult(type, key, options);
1686
- if (IsMappedKey(key))
1687
- return IndexFromMappedKey(type, key, options);
1688
- return CreateType(IsSchema(key) ? FromSchema(type, IndexPropertyKeys(key)) : FromSchema(type, key), options);
1689
- }
1690
-
1691
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/indexed/indexed-from-mapped-key.mjs
1692
- function MappedIndexPropertyKey(type, key, options) {
1693
- return { [key]: Index(type, [key], Clone(options)) };
1694
- }
1695
- function MappedIndexPropertyKeys(type, propertyKeys, options) {
1696
- return propertyKeys.reduce((result, left) => {
1697
- return { ...result, ...MappedIndexPropertyKey(type, left, options) };
1698
- }, {});
1699
- }
1700
- function MappedIndexProperties(type, mappedKey, options) {
1701
- return MappedIndexPropertyKeys(type, mappedKey.keys, options);
1702
- }
1703
- function IndexFromMappedKey(type, mappedKey, options) {
1704
- const properties = MappedIndexProperties(type, mappedKey, options);
1705
- return MappedResult(properties);
1706
- }
1707
-
1708
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/iterator/iterator.mjs
1709
- function Iterator(items, options) {
1710
- return CreateType({ [Kind]: "Iterator", type: "Iterator", items }, options);
1711
- }
1712
-
1713
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/object/object.mjs
1714
- function RequiredKeys(properties) {
1715
- const keys = [];
1716
- for (let key in properties) {
1717
- if (!IsOptional(properties[key]))
1718
- keys.push(key);
1719
- }
1720
- return keys;
1721
- }
1722
- function _Object(properties, options) {
1723
- const required = RequiredKeys(properties);
1724
- const schematic = required.length > 0 ? { [Kind]: "Object", type: "object", properties, required } : { [Kind]: "Object", type: "object", properties };
1725
- return CreateType(schematic, options);
1726
- }
1727
- var Object2 = _Object;
1728
-
1729
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/promise/promise.mjs
1730
- function Promise2(item, options) {
1731
- return CreateType({ [Kind]: "Promise", type: "Promise", item }, options);
1732
- }
1733
-
1734
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/readonly/readonly.mjs
1735
- function RemoveReadonly(schema) {
1736
- return CreateType(Discard(schema, [ReadonlyKind]));
1737
- }
1738
- function AddReadonly(schema) {
1739
- return CreateType({ ...schema, [ReadonlyKind]: "Readonly" });
1740
- }
1741
- function ReadonlyWithFlag(schema, F) {
1742
- return F === false ? RemoveReadonly(schema) : AddReadonly(schema);
1743
- }
1744
- function Readonly(schema, enable) {
1745
- const F = enable ?? true;
1746
- return IsMappedResult(schema) ? ReadonlyFromMappedResult(schema, F) : ReadonlyWithFlag(schema, F);
1747
- }
1748
-
1749
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/readonly/readonly-from-mapped-result.mjs
1750
- function FromProperties2(K, F) {
1751
- const Acc = {};
1752
- for (const K2 of globalThis.Object.getOwnPropertyNames(K))
1753
- Acc[K2] = Readonly(K[K2], F);
1754
- return Acc;
1755
- }
1756
- function FromMappedResult2(R, F) {
1757
- return FromProperties2(R.properties, F);
1758
- }
1759
- function ReadonlyFromMappedResult(R, F) {
1760
- const P = FromMappedResult2(R, F);
1761
- return MappedResult(P);
1762
- }
1763
-
1764
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/tuple/tuple.mjs
1765
- function Tuple(types, options) {
1766
- return CreateType(types.length > 0 ? { [Kind]: "Tuple", type: "array", items: types, additionalItems: false, minItems: types.length, maxItems: types.length } : { [Kind]: "Tuple", type: "array", minItems: types.length, maxItems: types.length }, options);
1767
- }
1768
-
1769
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/mapped/mapped.mjs
1770
- function FromMappedResult3(K, P) {
1771
- return K in P ? FromSchemaType(K, P[K]) : MappedResult(P);
1772
- }
1773
- function MappedKeyToKnownMappedResultProperties(K) {
1774
- return { [K]: Literal(K) };
1775
- }
1776
- function MappedKeyToUnknownMappedResultProperties(P) {
1777
- const Acc = {};
1778
- for (const L of P)
1779
- Acc[L] = Literal(L);
1780
- return Acc;
1781
- }
1782
- function MappedKeyToMappedResultProperties(K, P) {
1783
- return SetIncludes(P, K) ? MappedKeyToKnownMappedResultProperties(K) : MappedKeyToUnknownMappedResultProperties(P);
1784
- }
1785
- function FromMappedKey(K, P) {
1786
- const R = MappedKeyToMappedResultProperties(K, P);
1787
- return FromMappedResult3(K, R);
1788
- }
1789
- function FromRest2(K, T) {
1790
- return T.map((L) => FromSchemaType(K, L));
1791
- }
1792
- function FromProperties3(K, T) {
1793
- const Acc = {};
1794
- for (const K2 of globalThis.Object.getOwnPropertyNames(T))
1795
- Acc[K2] = FromSchemaType(K, T[K2]);
1796
- return Acc;
1797
- }
1798
- function FromSchemaType(K, T) {
1799
- const options = { ...T };
1800
- return (
1801
- // unevaluated modifier types
1802
- IsOptional(T) ? Optional(FromSchemaType(K, Discard(T, [OptionalKind]))) : IsReadonly(T) ? Readonly(FromSchemaType(K, Discard(T, [ReadonlyKind]))) : (
1803
- // unevaluated mapped types
1804
- IsMappedResult(T) ? FromMappedResult3(K, T.properties) : IsMappedKey(T) ? FromMappedKey(K, T.keys) : (
1805
- // unevaluated types
1806
- IsConstructor(T) ? Constructor(FromRest2(K, T.parameters), FromSchemaType(K, T.returns), options) : IsFunction2(T) ? Function(FromRest2(K, T.parameters), FromSchemaType(K, T.returns), options) : IsAsyncIterator2(T) ? AsyncIterator(FromSchemaType(K, T.items), options) : IsIterator2(T) ? Iterator(FromSchemaType(K, T.items), options) : IsIntersect(T) ? Intersect(FromRest2(K, T.allOf), options) : IsUnion(T) ? Union(FromRest2(K, T.anyOf), options) : IsTuple(T) ? Tuple(FromRest2(K, T.items ?? []), options) : IsObject3(T) ? Object2(FromProperties3(K, T.properties), options) : IsArray3(T) ? Array2(FromSchemaType(K, T.items), options) : IsPromise(T) ? Promise2(FromSchemaType(K, T.item), options) : T
1807
- )
1808
- )
1809
- );
1810
- }
1811
- function MappedFunctionReturnType(K, T) {
1812
- const Acc = {};
1813
- for (const L of K)
1814
- Acc[L] = FromSchemaType(L, T);
1815
- return Acc;
1816
- }
1817
- function Mapped(key, map, options) {
1818
- const K = IsSchema(key) ? IndexPropertyKeys(key) : key;
1819
- const RT = map({ [Kind]: "MappedKey", keys: K });
1820
- const R = MappedFunctionReturnType(K, RT);
1821
- return Object2(R, options);
1822
- }
1823
-
1824
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/optional/optional.mjs
1825
- function RemoveOptional(schema) {
1826
- return CreateType(Discard(schema, [OptionalKind]));
1827
- }
1828
- function AddOptional(schema) {
1829
- return CreateType({ ...schema, [OptionalKind]: "Optional" });
1830
- }
1831
- function OptionalWithFlag(schema, F) {
1832
- return F === false ? RemoveOptional(schema) : AddOptional(schema);
1833
- }
1834
- function Optional(schema, enable) {
1835
- const F = enable ?? true;
1836
- return IsMappedResult(schema) ? OptionalFromMappedResult(schema, F) : OptionalWithFlag(schema, F);
1837
- }
1838
-
1839
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/optional/optional-from-mapped-result.mjs
1840
- function FromProperties4(P, F) {
1841
- const Acc = {};
1842
- for (const K2 of globalThis.Object.getOwnPropertyNames(P))
1843
- Acc[K2] = Optional(P[K2], F);
1844
- return Acc;
1845
- }
1846
- function FromMappedResult4(R, F) {
1847
- return FromProperties4(R.properties, F);
1848
- }
1849
- function OptionalFromMappedResult(R, F) {
1850
- const P = FromMappedResult4(R, F);
1851
- return MappedResult(P);
1852
- }
1853
-
1854
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/intersect/intersect-create.mjs
1855
- function IntersectCreate(T, options = {}) {
1856
- const allObjects = T.every((schema) => IsObject3(schema));
1857
- const clonedUnevaluatedProperties = IsSchema(options.unevaluatedProperties) ? { unevaluatedProperties: options.unevaluatedProperties } : {};
1858
- return CreateType(options.unevaluatedProperties === false || IsSchema(options.unevaluatedProperties) || allObjects ? { ...clonedUnevaluatedProperties, [Kind]: "Intersect", type: "object", allOf: T } : { ...clonedUnevaluatedProperties, [Kind]: "Intersect", allOf: T }, options);
1859
- }
1860
-
1861
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/intersect/intersect-evaluated.mjs
1862
- function IsIntersectOptional(types) {
1863
- return types.every((left) => IsOptional(left));
1864
- }
1865
- function RemoveOptionalFromType2(type) {
1866
- return Discard(type, [OptionalKind]);
1867
- }
1868
- function RemoveOptionalFromRest2(types) {
1869
- return types.map((left) => IsOptional(left) ? RemoveOptionalFromType2(left) : left);
1870
- }
1871
- function ResolveIntersect(types, options) {
1872
- return IsIntersectOptional(types) ? Optional(IntersectCreate(RemoveOptionalFromRest2(types), options)) : IntersectCreate(RemoveOptionalFromRest2(types), options);
1873
- }
1874
- function IntersectEvaluated(types, options = {}) {
1875
- if (types.length === 1)
1876
- return CreateType(types[0], options);
1877
- if (types.length === 0)
1878
- return Never(options);
1879
- if (types.some((schema) => IsTransform(schema)))
1880
- throw new Error("Cannot intersect transform types");
1881
- return ResolveIntersect(types, options);
1882
- }
1883
-
1884
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/intersect/intersect.mjs
1885
- function Intersect(types, options) {
1886
- if (types.length === 1)
1887
- return CreateType(types[0], options);
1888
- if (types.length === 0)
1889
- return Never(options);
1890
- if (types.some((schema) => IsTransform(schema)))
1891
- throw new Error("Cannot intersect transform types");
1892
- return IntersectCreate(types, options);
1893
- }
1894
-
1895
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/ref/ref.mjs
1896
- function Ref(...args) {
1897
- const [$ref, options] = typeof args[0] === "string" ? [args[0], args[1]] : [args[0].$id, args[1]];
1898
- if (typeof $ref !== "string")
1899
- throw new TypeBoxError("Ref: $ref must be a string");
1900
- return CreateType({ [Kind]: "Ref", $ref }, options);
1901
- }
1902
-
1903
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/awaited/awaited.mjs
1904
- function FromComputed(target, parameters) {
1905
- return Computed("Awaited", [Computed(target, parameters)]);
1906
- }
1907
- function FromRef($ref) {
1908
- return Computed("Awaited", [Ref($ref)]);
1909
- }
1910
- function FromIntersect2(types) {
1911
- return Intersect(FromRest3(types));
1912
- }
1913
- function FromUnion4(types) {
1914
- return Union(FromRest3(types));
1915
- }
1916
- function FromPromise(type) {
1917
- return Awaited(type);
1918
- }
1919
- function FromRest3(types) {
1920
- return types.map((type) => Awaited(type));
1921
- }
1922
- function Awaited(type, options) {
1923
- return CreateType(IsComputed(type) ? FromComputed(type.target, type.parameters) : IsIntersect(type) ? FromIntersect2(type.allOf) : IsUnion(type) ? FromUnion4(type.anyOf) : IsPromise(type) ? FromPromise(type.item) : IsRef(type) ? FromRef(type.$ref) : type, options);
1924
- }
1925
-
1926
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/keyof/keyof-property-keys.mjs
1927
- function FromRest4(types) {
1928
- const result = [];
1929
- for (const L of types)
1930
- result.push(KeyOfPropertyKeys(L));
1931
- return result;
1932
- }
1933
- function FromIntersect3(types) {
1934
- const propertyKeysArray = FromRest4(types);
1935
- const propertyKeys = SetUnionMany(propertyKeysArray);
1936
- return propertyKeys;
1937
- }
1938
- function FromUnion5(types) {
1939
- const propertyKeysArray = FromRest4(types);
1940
- const propertyKeys = SetIntersectMany(propertyKeysArray);
1941
- return propertyKeys;
1942
- }
1943
- function FromTuple2(types) {
1944
- return types.map((_, indexer) => indexer.toString());
1945
- }
1946
- function FromArray2(_) {
1947
- return ["[number]"];
1948
- }
1949
- function FromProperties5(T) {
1950
- return globalThis.Object.getOwnPropertyNames(T);
1951
- }
1952
- function FromPatternProperties(patternProperties) {
1953
- if (!includePatternProperties)
1954
- return [];
1955
- const patternPropertyKeys = globalThis.Object.getOwnPropertyNames(patternProperties);
1956
- return patternPropertyKeys.map((key) => {
1957
- return key[0] === "^" && key[key.length - 1] === "$" ? key.slice(1, key.length - 1) : key;
1958
- });
1959
- }
1960
- function KeyOfPropertyKeys(type) {
1961
- return IsIntersect(type) ? FromIntersect3(type.allOf) : IsUnion(type) ? FromUnion5(type.anyOf) : IsTuple(type) ? FromTuple2(type.items ?? []) : IsArray3(type) ? FromArray2(type.items) : IsObject3(type) ? FromProperties5(type.properties) : IsRecord(type) ? FromPatternProperties(type.patternProperties) : [];
1962
- }
1963
- var includePatternProperties = false;
1964
-
1965
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/keyof/keyof.mjs
1966
- function FromComputed2(target, parameters) {
1967
- return Computed("KeyOf", [Computed(target, parameters)]);
1968
- }
1969
- function FromRef2($ref) {
1970
- return Computed("KeyOf", [Ref($ref)]);
1971
- }
1972
- function KeyOfFromType(type, options) {
1973
- const propertyKeys = KeyOfPropertyKeys(type);
1974
- const propertyKeyTypes = KeyOfPropertyKeysToRest(propertyKeys);
1975
- const result = UnionEvaluated(propertyKeyTypes);
1976
- return CreateType(result, options);
1977
- }
1978
- function KeyOfPropertyKeysToRest(propertyKeys) {
1979
- return propertyKeys.map((L) => L === "[number]" ? Number2() : Literal(L));
1980
- }
1981
- function KeyOf(type, options) {
1982
- return IsComputed(type) ? FromComputed2(type.target, type.parameters) : IsRef(type) ? FromRef2(type.$ref) : IsMappedResult(type) ? KeyOfFromMappedResult(type, options) : KeyOfFromType(type, options);
1983
- }
1984
-
1985
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/keyof/keyof-from-mapped-result.mjs
1986
- function FromProperties6(properties, options) {
1987
- const result = {};
1988
- for (const K2 of globalThis.Object.getOwnPropertyNames(properties))
1989
- result[K2] = KeyOf(properties[K2], Clone(options));
1990
- return result;
1991
- }
1992
- function FromMappedResult5(mappedResult, options) {
1993
- return FromProperties6(mappedResult.properties, options);
1994
- }
1995
- function KeyOfFromMappedResult(mappedResult, options) {
1996
- const properties = FromMappedResult5(mappedResult, options);
1997
- return MappedResult(properties);
1998
- }
1999
-
2000
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/composite/composite.mjs
2001
- function CompositeKeys(T) {
2002
- const Acc = [];
2003
- for (const L of T)
2004
- Acc.push(...KeyOfPropertyKeys(L));
2005
- return SetDistinct(Acc);
2006
- }
2007
- function FilterNever(T) {
2008
- return T.filter((L) => !IsNever(L));
2009
- }
2010
- function CompositeProperty(T, K) {
2011
- const Acc = [];
2012
- for (const L of T)
2013
- Acc.push(...IndexFromPropertyKeys(L, [K]));
2014
- return FilterNever(Acc);
2015
- }
2016
- function CompositeProperties(T, K) {
2017
- const Acc = {};
2018
- for (const L of K) {
2019
- Acc[L] = IntersectEvaluated(CompositeProperty(T, L));
2020
- }
2021
- return Acc;
2022
- }
2023
- function Composite(T, options) {
2024
- const K = CompositeKeys(T);
2025
- const P = CompositeProperties(T, K);
2026
- const R = Object2(P, options);
2027
- return R;
2028
- }
2029
-
2030
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/date/date.mjs
2031
- function Date2(options) {
2032
- return CreateType({ [Kind]: "Date", type: "Date" }, options);
2033
- }
2034
-
2035
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/null/null.mjs
2036
- function Null(options) {
2037
- return CreateType({ [Kind]: "Null", type: "null" }, options);
2038
- }
2039
-
2040
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/symbol/symbol.mjs
2041
- function Symbol2(options) {
2042
- return CreateType({ [Kind]: "Symbol", type: "symbol" }, options);
2043
- }
2044
-
2045
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/undefined/undefined.mjs
2046
- function Undefined(options) {
2047
- return CreateType({ [Kind]: "Undefined", type: "undefined" }, options);
2048
- }
2049
-
2050
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/uint8array/uint8array.mjs
2051
- function Uint8Array2(options) {
2052
- return CreateType({ [Kind]: "Uint8Array", type: "Uint8Array" }, options);
2053
- }
2054
-
2055
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/unknown/unknown.mjs
2056
- function Unknown(options) {
2057
- return CreateType({ [Kind]: "Unknown" }, options);
2058
- }
2059
-
2060
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/const/const.mjs
2061
- function FromArray3(T) {
2062
- return T.map((L) => FromValue(L, false));
2063
- }
2064
- function FromProperties7(value) {
2065
- const Acc = {};
2066
- for (const K of globalThis.Object.getOwnPropertyNames(value))
2067
- Acc[K] = Readonly(FromValue(value[K], false));
2068
- return Acc;
2069
- }
2070
- function ConditionalReadonly(T, root) {
2071
- return root === true ? T : Readonly(T);
2072
- }
2073
- function FromValue(value, root) {
2074
- return IsAsyncIterator(value) ? ConditionalReadonly(Any(), root) : IsIterator(value) ? ConditionalReadonly(Any(), root) : IsArray(value) ? Readonly(Tuple(FromArray3(value))) : IsUint8Array(value) ? Uint8Array2() : IsDate(value) ? Date2() : IsObject(value) ? ConditionalReadonly(Object2(FromProperties7(value)), root) : IsFunction(value) ? ConditionalReadonly(Function([], Unknown()), root) : IsUndefined(value) ? Undefined() : IsNull(value) ? Null() : IsSymbol(value) ? Symbol2() : IsBigInt(value) ? BigInt() : IsNumber(value) ? Literal(value) : IsBoolean(value) ? Literal(value) : IsString(value) ? Literal(value) : Object2({});
2075
- }
2076
- function Const(T, options) {
2077
- return CreateType(FromValue(T, true), options);
2078
- }
2079
-
2080
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/constructor-parameters/constructor-parameters.mjs
2081
- function ConstructorParameters(schema, options) {
2082
- return IsConstructor(schema) ? Tuple(schema.parameters, options) : Never(options);
2083
- }
2084
-
2085
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/enum/enum.mjs
2086
- function Enum(item, options) {
2087
- if (IsUndefined(item))
2088
- throw new Error("Enum undefined or empty");
2089
- const values1 = globalThis.Object.getOwnPropertyNames(item).filter((key) => isNaN(key)).map((key) => item[key]);
2090
- const values2 = [...new Set(values1)];
2091
- const anyOf = values2.map((value) => Literal(value));
2092
- return Union(anyOf, { ...options, [Hint]: "Enum" });
2093
- }
2094
-
2095
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/extends/extends-check.mjs
2096
- var ExtendsResolverError = class extends TypeBoxError {
2097
- };
2098
- var ExtendsResult;
2099
- (function(ExtendsResult2) {
2100
- ExtendsResult2[ExtendsResult2["Union"] = 0] = "Union";
2101
- ExtendsResult2[ExtendsResult2["True"] = 1] = "True";
2102
- ExtendsResult2[ExtendsResult2["False"] = 2] = "False";
2103
- })(ExtendsResult || (ExtendsResult = {}));
2104
- function IntoBooleanResult(result) {
2105
- return result === ExtendsResult.False ? result : ExtendsResult.True;
2106
- }
2107
- function Throw(message) {
2108
- throw new ExtendsResolverError(message);
2109
- }
2110
- function IsStructuralRight(right) {
2111
- return type_exports.IsNever(right) || type_exports.IsIntersect(right) || type_exports.IsUnion(right) || type_exports.IsUnknown(right) || type_exports.IsAny(right);
2112
- }
2113
- function StructuralRight(left, right) {
2114
- return type_exports.IsNever(right) ? FromNeverRight(left, right) : type_exports.IsIntersect(right) ? FromIntersectRight(left, right) : type_exports.IsUnion(right) ? FromUnionRight(left, right) : type_exports.IsUnknown(right) ? FromUnknownRight(left, right) : type_exports.IsAny(right) ? FromAnyRight(left, right) : Throw("StructuralRight");
2115
- }
2116
- function FromAnyRight(left, right) {
2117
- return ExtendsResult.True;
2118
- }
2119
- function FromAny(left, right) {
2120
- return type_exports.IsIntersect(right) ? FromIntersectRight(left, right) : type_exports.IsUnion(right) && right.anyOf.some((schema) => type_exports.IsAny(schema) || type_exports.IsUnknown(schema)) ? ExtendsResult.True : type_exports.IsUnion(right) ? ExtendsResult.Union : type_exports.IsUnknown(right) ? ExtendsResult.True : type_exports.IsAny(right) ? ExtendsResult.True : ExtendsResult.Union;
2121
- }
2122
- function FromArrayRight(left, right) {
2123
- return type_exports.IsUnknown(left) ? ExtendsResult.False : type_exports.IsAny(left) ? ExtendsResult.Union : type_exports.IsNever(left) ? ExtendsResult.True : ExtendsResult.False;
2124
- }
2125
- function FromArray4(left, right) {
2126
- return type_exports.IsObject(right) && IsObjectArrayLike(right) ? ExtendsResult.True : IsStructuralRight(right) ? StructuralRight(left, right) : !type_exports.IsArray(right) ? ExtendsResult.False : IntoBooleanResult(Visit3(left.items, right.items));
2127
- }
2128
- function FromAsyncIterator(left, right) {
2129
- return IsStructuralRight(right) ? StructuralRight(left, right) : !type_exports.IsAsyncIterator(right) ? ExtendsResult.False : IntoBooleanResult(Visit3(left.items, right.items));
2130
- }
2131
- function FromBigInt(left, right) {
2132
- return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsBigInt(right) ? ExtendsResult.True : ExtendsResult.False;
2133
- }
2134
- function FromBooleanRight(left, right) {
2135
- return type_exports.IsLiteralBoolean(left) ? ExtendsResult.True : type_exports.IsBoolean(left) ? ExtendsResult.True : ExtendsResult.False;
2136
- }
2137
- function FromBoolean(left, right) {
2138
- return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsBoolean(right) ? ExtendsResult.True : ExtendsResult.False;
2139
- }
2140
- function FromConstructor(left, right) {
2141
- return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : !type_exports.IsConstructor(right) ? ExtendsResult.False : left.parameters.length > right.parameters.length ? ExtendsResult.False : !left.parameters.every((schema, index9) => IntoBooleanResult(Visit3(right.parameters[index9], schema)) === ExtendsResult.True) ? ExtendsResult.False : IntoBooleanResult(Visit3(left.returns, right.returns));
2142
- }
2143
- function FromDate(left, right) {
2144
- return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsDate(right) ? ExtendsResult.True : ExtendsResult.False;
2145
- }
2146
- function FromFunction(left, right) {
2147
- return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : !type_exports.IsFunction(right) ? ExtendsResult.False : left.parameters.length > right.parameters.length ? ExtendsResult.False : !left.parameters.every((schema, index9) => IntoBooleanResult(Visit3(right.parameters[index9], schema)) === ExtendsResult.True) ? ExtendsResult.False : IntoBooleanResult(Visit3(left.returns, right.returns));
2148
- }
2149
- function FromIntegerRight(left, right) {
2150
- return type_exports.IsLiteral(left) && value_exports.IsNumber(left.const) ? ExtendsResult.True : type_exports.IsNumber(left) || type_exports.IsInteger(left) ? ExtendsResult.True : ExtendsResult.False;
2151
- }
2152
- function FromInteger(left, right) {
2153
- return type_exports.IsInteger(right) || type_exports.IsNumber(right) ? ExtendsResult.True : IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : ExtendsResult.False;
2154
- }
2155
- function FromIntersectRight(left, right) {
2156
- return right.allOf.every((schema) => Visit3(left, schema) === ExtendsResult.True) ? ExtendsResult.True : ExtendsResult.False;
2157
- }
2158
- function FromIntersect4(left, right) {
2159
- return left.allOf.some((schema) => Visit3(schema, right) === ExtendsResult.True) ? ExtendsResult.True : ExtendsResult.False;
2160
- }
2161
- function FromIterator(left, right) {
2162
- return IsStructuralRight(right) ? StructuralRight(left, right) : !type_exports.IsIterator(right) ? ExtendsResult.False : IntoBooleanResult(Visit3(left.items, right.items));
2163
- }
2164
- function FromLiteral2(left, right) {
2165
- return type_exports.IsLiteral(right) && right.const === left.const ? ExtendsResult.True : IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsString(right) ? FromStringRight(left, right) : type_exports.IsNumber(right) ? FromNumberRight(left, right) : type_exports.IsInteger(right) ? FromIntegerRight(left, right) : type_exports.IsBoolean(right) ? FromBooleanRight(left, right) : ExtendsResult.False;
2166
- }
2167
- function FromNeverRight(left, right) {
2168
- return ExtendsResult.False;
2169
- }
2170
- function FromNever(left, right) {
2171
- return ExtendsResult.True;
2172
- }
2173
- function UnwrapTNot(schema) {
2174
- let [current, depth] = [schema, 0];
2175
- while (true) {
2176
- if (!type_exports.IsNot(current))
2177
- break;
2178
- current = current.not;
2179
- depth += 1;
2180
- }
2181
- return depth % 2 === 0 ? current : Unknown();
2182
- }
2183
- function FromNot(left, right) {
2184
- return type_exports.IsNot(left) ? Visit3(UnwrapTNot(left), right) : type_exports.IsNot(right) ? Visit3(left, UnwrapTNot(right)) : Throw("Invalid fallthrough for Not");
2185
- }
2186
- function FromNull(left, right) {
2187
- return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsNull(right) ? ExtendsResult.True : ExtendsResult.False;
2188
- }
2189
- function FromNumberRight(left, right) {
2190
- return type_exports.IsLiteralNumber(left) ? ExtendsResult.True : type_exports.IsNumber(left) || type_exports.IsInteger(left) ? ExtendsResult.True : ExtendsResult.False;
2191
- }
2192
- function FromNumber(left, right) {
2193
- return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsInteger(right) || type_exports.IsNumber(right) ? ExtendsResult.True : ExtendsResult.False;
2194
- }
2195
- function IsObjectPropertyCount(schema, count) {
2196
- return Object.getOwnPropertyNames(schema.properties).length === count;
2197
- }
2198
- function IsObjectStringLike(schema) {
2199
- return IsObjectArrayLike(schema);
2200
- }
2201
- function IsObjectSymbolLike(schema) {
2202
- return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "description" in schema.properties && type_exports.IsUnion(schema.properties.description) && schema.properties.description.anyOf.length === 2 && (type_exports.IsString(schema.properties.description.anyOf[0]) && type_exports.IsUndefined(schema.properties.description.anyOf[1]) || type_exports.IsString(schema.properties.description.anyOf[1]) && type_exports.IsUndefined(schema.properties.description.anyOf[0]));
2203
- }
2204
- function IsObjectNumberLike(schema) {
2205
- return IsObjectPropertyCount(schema, 0);
2206
- }
2207
- function IsObjectBooleanLike(schema) {
2208
- return IsObjectPropertyCount(schema, 0);
2209
- }
2210
- function IsObjectBigIntLike(schema) {
2211
- return IsObjectPropertyCount(schema, 0);
2212
- }
2213
- function IsObjectDateLike(schema) {
2214
- return IsObjectPropertyCount(schema, 0);
2215
- }
2216
- function IsObjectUint8ArrayLike(schema) {
2217
- return IsObjectArrayLike(schema);
2218
- }
2219
- function IsObjectFunctionLike(schema) {
2220
- const length = Number2();
2221
- return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "length" in schema.properties && IntoBooleanResult(Visit3(schema.properties["length"], length)) === ExtendsResult.True;
2222
- }
2223
- function IsObjectConstructorLike(schema) {
2224
- return IsObjectPropertyCount(schema, 0);
2225
- }
2226
- function IsObjectArrayLike(schema) {
2227
- const length = Number2();
2228
- return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "length" in schema.properties && IntoBooleanResult(Visit3(schema.properties["length"], length)) === ExtendsResult.True;
2229
- }
2230
- function IsObjectPromiseLike(schema) {
2231
- const then = Function([Any()], Any());
2232
- return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "then" in schema.properties && IntoBooleanResult(Visit3(schema.properties["then"], then)) === ExtendsResult.True;
2233
- }
2234
- function Property(left, right) {
2235
- return Visit3(left, right) === ExtendsResult.False ? ExtendsResult.False : type_exports.IsOptional(left) && !type_exports.IsOptional(right) ? ExtendsResult.False : ExtendsResult.True;
2236
- }
2237
- function FromObjectRight(left, right) {
2238
- return type_exports.IsUnknown(left) ? ExtendsResult.False : type_exports.IsAny(left) ? ExtendsResult.Union : type_exports.IsNever(left) || type_exports.IsLiteralString(left) && IsObjectStringLike(right) || type_exports.IsLiteralNumber(left) && IsObjectNumberLike(right) || type_exports.IsLiteralBoolean(left) && IsObjectBooleanLike(right) || type_exports.IsSymbol(left) && IsObjectSymbolLike(right) || type_exports.IsBigInt(left) && IsObjectBigIntLike(right) || type_exports.IsString(left) && IsObjectStringLike(right) || type_exports.IsSymbol(left) && IsObjectSymbolLike(right) || type_exports.IsNumber(left) && IsObjectNumberLike(right) || type_exports.IsInteger(left) && IsObjectNumberLike(right) || type_exports.IsBoolean(left) && IsObjectBooleanLike(right) || type_exports.IsUint8Array(left) && IsObjectUint8ArrayLike(right) || type_exports.IsDate(left) && IsObjectDateLike(right) || type_exports.IsConstructor(left) && IsObjectConstructorLike(right) || type_exports.IsFunction(left) && IsObjectFunctionLike(right) ? ExtendsResult.True : type_exports.IsRecord(left) && type_exports.IsString(RecordKey(left)) ? (() => {
2239
- return right[Hint] === "Record" ? ExtendsResult.True : ExtendsResult.False;
2240
- })() : type_exports.IsRecord(left) && type_exports.IsNumber(RecordKey(left)) ? (() => {
2241
- return IsObjectPropertyCount(right, 0) ? ExtendsResult.True : ExtendsResult.False;
2242
- })() : ExtendsResult.False;
2243
- }
2244
- function FromObject(left, right) {
2245
- return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : !type_exports.IsObject(right) ? ExtendsResult.False : (() => {
2246
- for (const key of Object.getOwnPropertyNames(right.properties)) {
2247
- if (!(key in left.properties) && !type_exports.IsOptional(right.properties[key])) {
2248
- return ExtendsResult.False;
2249
- }
2250
- if (type_exports.IsOptional(right.properties[key])) {
2251
- return ExtendsResult.True;
2252
- }
2253
- if (Property(left.properties[key], right.properties[key]) === ExtendsResult.False) {
2254
- return ExtendsResult.False;
2255
- }
2256
- }
2257
- return ExtendsResult.True;
2258
- })();
2259
- }
2260
- function FromPromise2(left, right) {
2261
- return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) && IsObjectPromiseLike(right) ? ExtendsResult.True : !type_exports.IsPromise(right) ? ExtendsResult.False : IntoBooleanResult(Visit3(left.item, right.item));
2262
- }
2263
- function RecordKey(schema) {
2264
- return PatternNumberExact in schema.patternProperties ? Number2() : PatternStringExact in schema.patternProperties ? String2() : Throw("Unknown record key pattern");
2265
- }
2266
- function RecordValue(schema) {
2267
- return PatternNumberExact in schema.patternProperties ? schema.patternProperties[PatternNumberExact] : PatternStringExact in schema.patternProperties ? schema.patternProperties[PatternStringExact] : Throw("Unable to get record value schema");
2268
- }
2269
- function FromRecordRight(left, right) {
2270
- const [Key, Value] = [RecordKey(right), RecordValue(right)];
2271
- return type_exports.IsLiteralString(left) && type_exports.IsNumber(Key) && IntoBooleanResult(Visit3(left, Value)) === ExtendsResult.True ? ExtendsResult.True : type_exports.IsUint8Array(left) && type_exports.IsNumber(Key) ? Visit3(left, Value) : type_exports.IsString(left) && type_exports.IsNumber(Key) ? Visit3(left, Value) : type_exports.IsArray(left) && type_exports.IsNumber(Key) ? Visit3(left, Value) : type_exports.IsObject(left) ? (() => {
2272
- for (const key of Object.getOwnPropertyNames(left.properties)) {
2273
- if (Property(Value, left.properties[key]) === ExtendsResult.False) {
2274
- return ExtendsResult.False;
2275
- }
2276
- }
2277
- return ExtendsResult.True;
2278
- })() : ExtendsResult.False;
2279
- }
2280
- function FromRecord(left, right) {
2281
- return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : !type_exports.IsRecord(right) ? ExtendsResult.False : Visit3(RecordValue(left), RecordValue(right));
2282
- }
2283
- function FromRegExp(left, right) {
2284
- const L = type_exports.IsRegExp(left) ? String2() : left;
2285
- const R = type_exports.IsRegExp(right) ? String2() : right;
2286
- return Visit3(L, R);
2287
- }
2288
- function FromStringRight(left, right) {
2289
- return type_exports.IsLiteral(left) && value_exports.IsString(left.const) ? ExtendsResult.True : type_exports.IsString(left) ? ExtendsResult.True : ExtendsResult.False;
2290
- }
2291
- function FromString(left, right) {
2292
- return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsString(right) ? ExtendsResult.True : ExtendsResult.False;
2293
- }
2294
- function FromSymbol(left, right) {
2295
- return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsSymbol(right) ? ExtendsResult.True : ExtendsResult.False;
2296
- }
2297
- function FromTemplateLiteral2(left, right) {
2298
- return type_exports.IsTemplateLiteral(left) ? Visit3(TemplateLiteralToUnion(left), right) : type_exports.IsTemplateLiteral(right) ? Visit3(left, TemplateLiteralToUnion(right)) : Throw("Invalid fallthrough for TemplateLiteral");
2299
- }
2300
- function IsArrayOfTuple(left, right) {
2301
- return type_exports.IsArray(right) && left.items !== void 0 && left.items.every((schema) => Visit3(schema, right.items) === ExtendsResult.True);
2302
- }
2303
- function FromTupleRight(left, right) {
2304
- return type_exports.IsNever(left) ? ExtendsResult.True : type_exports.IsUnknown(left) ? ExtendsResult.False : type_exports.IsAny(left) ? ExtendsResult.Union : ExtendsResult.False;
2305
- }
2306
- function FromTuple3(left, right) {
2307
- return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) && IsObjectArrayLike(right) ? ExtendsResult.True : type_exports.IsArray(right) && IsArrayOfTuple(left, right) ? ExtendsResult.True : !type_exports.IsTuple(right) ? ExtendsResult.False : value_exports.IsUndefined(left.items) && !value_exports.IsUndefined(right.items) || !value_exports.IsUndefined(left.items) && value_exports.IsUndefined(right.items) ? ExtendsResult.False : value_exports.IsUndefined(left.items) && !value_exports.IsUndefined(right.items) ? ExtendsResult.True : left.items.every((schema, index9) => Visit3(schema, right.items[index9]) === ExtendsResult.True) ? ExtendsResult.True : ExtendsResult.False;
2308
- }
2309
- function FromUint8Array(left, right) {
2310
- return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsUint8Array(right) ? ExtendsResult.True : ExtendsResult.False;
2311
- }
2312
- function FromUndefined(left, right) {
2313
- return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsVoid(right) ? FromVoidRight(left, right) : type_exports.IsUndefined(right) ? ExtendsResult.True : ExtendsResult.False;
2314
- }
2315
- function FromUnionRight(left, right) {
2316
- return right.anyOf.some((schema) => Visit3(left, schema) === ExtendsResult.True) ? ExtendsResult.True : ExtendsResult.False;
2317
- }
2318
- function FromUnion6(left, right) {
2319
- return left.anyOf.every((schema) => Visit3(schema, right) === ExtendsResult.True) ? ExtendsResult.True : ExtendsResult.False;
2320
- }
2321
- function FromUnknownRight(left, right) {
2322
- return ExtendsResult.True;
2323
- }
2324
- function FromUnknown(left, right) {
2325
- return type_exports.IsNever(right) ? FromNeverRight(left, right) : type_exports.IsIntersect(right) ? FromIntersectRight(left, right) : type_exports.IsUnion(right) ? FromUnionRight(left, right) : type_exports.IsAny(right) ? FromAnyRight(left, right) : type_exports.IsString(right) ? FromStringRight(left, right) : type_exports.IsNumber(right) ? FromNumberRight(left, right) : type_exports.IsInteger(right) ? FromIntegerRight(left, right) : type_exports.IsBoolean(right) ? FromBooleanRight(left, right) : type_exports.IsArray(right) ? FromArrayRight(left, right) : type_exports.IsTuple(right) ? FromTupleRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsUnknown(right) ? ExtendsResult.True : ExtendsResult.False;
2326
- }
2327
- function FromVoidRight(left, right) {
2328
- return type_exports.IsUndefined(left) ? ExtendsResult.True : type_exports.IsUndefined(left) ? ExtendsResult.True : ExtendsResult.False;
2329
- }
2330
- function FromVoid(left, right) {
2331
- return type_exports.IsIntersect(right) ? FromIntersectRight(left, right) : type_exports.IsUnion(right) ? FromUnionRight(left, right) : type_exports.IsUnknown(right) ? FromUnknownRight(left, right) : type_exports.IsAny(right) ? FromAnyRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsVoid(right) ? ExtendsResult.True : ExtendsResult.False;
2332
- }
2333
- function Visit3(left, right) {
2334
- return (
2335
- // resolvable
2336
- type_exports.IsTemplateLiteral(left) || type_exports.IsTemplateLiteral(right) ? FromTemplateLiteral2(left, right) : type_exports.IsRegExp(left) || type_exports.IsRegExp(right) ? FromRegExp(left, right) : type_exports.IsNot(left) || type_exports.IsNot(right) ? FromNot(left, right) : (
2337
- // standard
2338
- type_exports.IsAny(left) ? FromAny(left, right) : type_exports.IsArray(left) ? FromArray4(left, right) : type_exports.IsBigInt(left) ? FromBigInt(left, right) : type_exports.IsBoolean(left) ? FromBoolean(left, right) : type_exports.IsAsyncIterator(left) ? FromAsyncIterator(left, right) : type_exports.IsConstructor(left) ? FromConstructor(left, right) : type_exports.IsDate(left) ? FromDate(left, right) : type_exports.IsFunction(left) ? FromFunction(left, right) : type_exports.IsInteger(left) ? FromInteger(left, right) : type_exports.IsIntersect(left) ? FromIntersect4(left, right) : type_exports.IsIterator(left) ? FromIterator(left, right) : type_exports.IsLiteral(left) ? FromLiteral2(left, right) : type_exports.IsNever(left) ? FromNever(left, right) : type_exports.IsNull(left) ? FromNull(left, right) : type_exports.IsNumber(left) ? FromNumber(left, right) : type_exports.IsObject(left) ? FromObject(left, right) : type_exports.IsRecord(left) ? FromRecord(left, right) : type_exports.IsString(left) ? FromString(left, right) : type_exports.IsSymbol(left) ? FromSymbol(left, right) : type_exports.IsTuple(left) ? FromTuple3(left, right) : type_exports.IsPromise(left) ? FromPromise2(left, right) : type_exports.IsUint8Array(left) ? FromUint8Array(left, right) : type_exports.IsUndefined(left) ? FromUndefined(left, right) : type_exports.IsUnion(left) ? FromUnion6(left, right) : type_exports.IsUnknown(left) ? FromUnknown(left, right) : type_exports.IsVoid(left) ? FromVoid(left, right) : Throw(`Unknown left type operand '${left[Kind]}'`)
2339
- )
2340
- );
2341
- }
2342
- function ExtendsCheck(left, right) {
2343
- return Visit3(left, right);
2344
- }
2345
-
2346
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/extends/extends-from-mapped-result.mjs
2347
- function FromProperties8(P, Right, True, False, options) {
2348
- const Acc = {};
2349
- for (const K2 of globalThis.Object.getOwnPropertyNames(P))
2350
- Acc[K2] = Extends(P[K2], Right, True, False, Clone(options));
2351
- return Acc;
2352
- }
2353
- function FromMappedResult6(Left, Right, True, False, options) {
2354
- return FromProperties8(Left.properties, Right, True, False, options);
2355
- }
2356
- function ExtendsFromMappedResult(Left, Right, True, False, options) {
2357
- const P = FromMappedResult6(Left, Right, True, False, options);
2358
- return MappedResult(P);
2359
- }
2360
-
2361
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/extends/extends.mjs
2362
- function ExtendsResolve(left, right, trueType, falseType) {
2363
- const R = ExtendsCheck(left, right);
2364
- return R === ExtendsResult.Union ? Union([trueType, falseType]) : R === ExtendsResult.True ? trueType : falseType;
2365
- }
2366
- function Extends(L, R, T, F, options) {
2367
- return IsMappedResult(L) ? ExtendsFromMappedResult(L, R, T, F, options) : IsMappedKey(L) ? CreateType(ExtendsFromMappedKey(L, R, T, F, options)) : CreateType(ExtendsResolve(L, R, T, F), options);
2368
- }
2369
-
2370
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/extends/extends-from-mapped-key.mjs
2371
- function FromPropertyKey(K, U, L, R, options) {
2372
- return {
2373
- [K]: Extends(Literal(K), U, L, R, Clone(options))
2374
- };
2375
- }
2376
- function FromPropertyKeys(K, U, L, R, options) {
2377
- return K.reduce((Acc, LK) => {
2378
- return { ...Acc, ...FromPropertyKey(LK, U, L, R, options) };
2379
- }, {});
2380
- }
2381
- function FromMappedKey2(K, U, L, R, options) {
2382
- return FromPropertyKeys(K.keys, U, L, R, options);
2383
- }
2384
- function ExtendsFromMappedKey(T, U, L, R, options) {
2385
- const P = FromMappedKey2(T, U, L, R, options);
2386
- return MappedResult(P);
2387
- }
2388
-
2389
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/exclude/exclude-from-template-literal.mjs
2390
- function ExcludeFromTemplateLiteral(L, R) {
2391
- return Exclude(TemplateLiteralToUnion(L), R);
2392
- }
2393
-
2394
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/exclude/exclude.mjs
2395
- function ExcludeRest(L, R) {
2396
- const excluded = L.filter((inner) => ExtendsCheck(inner, R) === ExtendsResult.False);
2397
- return excluded.length === 1 ? excluded[0] : Union(excluded);
2398
- }
2399
- function Exclude(L, R, options = {}) {
2400
- if (IsTemplateLiteral(L))
2401
- return CreateType(ExcludeFromTemplateLiteral(L, R), options);
2402
- if (IsMappedResult(L))
2403
- return CreateType(ExcludeFromMappedResult(L, R), options);
2404
- return CreateType(IsUnion(L) ? ExcludeRest(L.anyOf, R) : ExtendsCheck(L, R) !== ExtendsResult.False ? Never() : L, options);
2405
- }
2406
-
2407
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/exclude/exclude-from-mapped-result.mjs
2408
- function FromProperties9(P, U) {
2409
- const Acc = {};
2410
- for (const K2 of globalThis.Object.getOwnPropertyNames(P))
2411
- Acc[K2] = Exclude(P[K2], U);
2412
- return Acc;
2413
- }
2414
- function FromMappedResult7(R, T) {
2415
- return FromProperties9(R.properties, T);
2416
- }
2417
- function ExcludeFromMappedResult(R, T) {
2418
- const P = FromMappedResult7(R, T);
2419
- return MappedResult(P);
2420
- }
2421
-
2422
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/extract/extract-from-template-literal.mjs
2423
- function ExtractFromTemplateLiteral(L, R) {
2424
- return Extract(TemplateLiteralToUnion(L), R);
2425
- }
2426
-
2427
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/extract/extract.mjs
2428
- function ExtractRest(L, R) {
2429
- const extracted = L.filter((inner) => ExtendsCheck(inner, R) !== ExtendsResult.False);
2430
- return extracted.length === 1 ? extracted[0] : Union(extracted);
2431
- }
2432
- function Extract(L, R, options) {
2433
- if (IsTemplateLiteral(L))
2434
- return CreateType(ExtractFromTemplateLiteral(L, R), options);
2435
- if (IsMappedResult(L))
2436
- return CreateType(ExtractFromMappedResult(L, R), options);
2437
- return CreateType(IsUnion(L) ? ExtractRest(L.anyOf, R) : ExtendsCheck(L, R) !== ExtendsResult.False ? L : Never(), options);
2438
- }
2439
-
2440
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/extract/extract-from-mapped-result.mjs
2441
- function FromProperties10(P, T) {
2442
- const Acc = {};
2443
- for (const K2 of globalThis.Object.getOwnPropertyNames(P))
2444
- Acc[K2] = Extract(P[K2], T);
2445
- return Acc;
2446
- }
2447
- function FromMappedResult8(R, T) {
2448
- return FromProperties10(R.properties, T);
2449
- }
2450
- function ExtractFromMappedResult(R, T) {
2451
- const P = FromMappedResult8(R, T);
2452
- return MappedResult(P);
2453
- }
2454
-
2455
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/instance-type/instance-type.mjs
2456
- function InstanceType(schema, options) {
2457
- return IsConstructor(schema) ? CreateType(schema.returns, options) : Never(options);
2458
- }
2459
-
2460
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/readonly-optional/readonly-optional.mjs
2461
- function ReadonlyOptional(schema) {
2462
- return Readonly(Optional(schema));
2463
- }
2464
-
2465
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/record/record.mjs
2466
- function RecordCreateFromPattern(pattern, T, options) {
2467
- return CreateType({ [Kind]: "Record", type: "object", patternProperties: { [pattern]: T } }, options);
2468
- }
2469
- function RecordCreateFromKeys(K, T, options) {
2470
- const result = {};
2471
- for (const K2 of K)
2472
- result[K2] = T;
2473
- return Object2(result, { ...options, [Hint]: "Record" });
2474
- }
2475
- function FromTemplateLiteralKey(K, T, options) {
2476
- return IsTemplateLiteralFinite(K) ? RecordCreateFromKeys(IndexPropertyKeys(K), T, options) : RecordCreateFromPattern(K.pattern, T, options);
2477
- }
2478
- function FromUnionKey(key, type, options) {
2479
- return RecordCreateFromKeys(IndexPropertyKeys(Union(key)), type, options);
2480
- }
2481
- function FromLiteralKey(key, type, options) {
2482
- return RecordCreateFromKeys([key.toString()], type, options);
2483
- }
2484
- function FromRegExpKey(key, type, options) {
2485
- return RecordCreateFromPattern(key.source, type, options);
2486
- }
2487
- function FromStringKey(key, type, options) {
2488
- const pattern = IsUndefined(key.pattern) ? PatternStringExact : key.pattern;
2489
- return RecordCreateFromPattern(pattern, type, options);
2490
- }
2491
- function FromAnyKey(_, type, options) {
2492
- return RecordCreateFromPattern(PatternStringExact, type, options);
2493
- }
2494
- function FromNeverKey(_key, type, options) {
2495
- return RecordCreateFromPattern(PatternNeverExact, type, options);
2496
- }
2497
- function FromBooleanKey(_key, type, options) {
2498
- return Object2({ true: type, false: type }, options);
2499
- }
2500
- function FromIntegerKey(_key, type, options) {
2501
- return RecordCreateFromPattern(PatternNumberExact, type, options);
2502
- }
2503
- function FromNumberKey(_, type, options) {
2504
- return RecordCreateFromPattern(PatternNumberExact, type, options);
2505
- }
2506
- function Record(key, type, options = {}) {
2507
- return IsUnion(key) ? FromUnionKey(key.anyOf, type, options) : IsTemplateLiteral(key) ? FromTemplateLiteralKey(key, type, options) : IsLiteral(key) ? FromLiteralKey(key.const, type, options) : IsBoolean2(key) ? FromBooleanKey(key, type, options) : IsInteger(key) ? FromIntegerKey(key, type, options) : IsNumber3(key) ? FromNumberKey(key, type, options) : IsRegExp2(key) ? FromRegExpKey(key, type, options) : IsString2(key) ? FromStringKey(key, type, options) : IsAny(key) ? FromAnyKey(key, type, options) : IsNever(key) ? FromNeverKey(key, type, options) : Never(options);
2508
- }
2509
- function RecordPattern(record) {
2510
- return globalThis.Object.getOwnPropertyNames(record.patternProperties)[0];
2511
- }
2512
- function RecordKey2(type) {
2513
- const pattern = RecordPattern(type);
2514
- return pattern === PatternStringExact ? String2() : pattern === PatternNumberExact ? Number2() : String2({ pattern });
2515
- }
2516
- function RecordValue2(type) {
2517
- return type.patternProperties[RecordPattern(type)];
2518
- }
2519
-
2520
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/instantiate/instantiate.mjs
2521
- function FromConstructor2(args, type) {
2522
- type.parameters = FromTypes(args, type.parameters);
2523
- type.returns = FromType(args, type.returns);
2524
- return type;
2525
- }
2526
- function FromFunction2(args, type) {
2527
- type.parameters = FromTypes(args, type.parameters);
2528
- type.returns = FromType(args, type.returns);
2529
- return type;
2530
- }
2531
- function FromIntersect5(args, type) {
2532
- type.allOf = FromTypes(args, type.allOf);
2533
- return type;
2534
- }
2535
- function FromUnion7(args, type) {
2536
- type.anyOf = FromTypes(args, type.anyOf);
2537
- return type;
2538
- }
2539
- function FromTuple4(args, type) {
2540
- if (IsUndefined(type.items))
2541
- return type;
2542
- type.items = FromTypes(args, type.items);
2543
- return type;
2544
- }
2545
- function FromArray5(args, type) {
2546
- type.items = FromType(args, type.items);
2547
- return type;
2548
- }
2549
- function FromAsyncIterator2(args, type) {
2550
- type.items = FromType(args, type.items);
2551
- return type;
2552
- }
2553
- function FromIterator2(args, type) {
2554
- type.items = FromType(args, type.items);
2555
- return type;
2556
- }
2557
- function FromPromise3(args, type) {
2558
- type.item = FromType(args, type.item);
2559
- return type;
2560
- }
2561
- function FromObject2(args, type) {
2562
- const mappedProperties = FromProperties11(args, type.properties);
2563
- return { ...type, ...Object2(mappedProperties) };
2564
- }
2565
- function FromRecord2(args, type) {
2566
- const mappedKey = FromType(args, RecordKey2(type));
2567
- const mappedValue = FromType(args, RecordValue2(type));
2568
- const result = Record(mappedKey, mappedValue);
2569
- return { ...type, ...result };
2570
- }
2571
- function FromArgument(args, argument) {
2572
- return argument.index in args ? args[argument.index] : Unknown();
2573
- }
2574
- function FromProperty2(args, type) {
2575
- const isReadonly = IsReadonly(type);
2576
- const isOptional = IsOptional(type);
2577
- const mapped = FromType(args, type);
2578
- return isReadonly && isOptional ? ReadonlyOptional(mapped) : isReadonly && !isOptional ? Readonly(mapped) : !isReadonly && isOptional ? Optional(mapped) : mapped;
2579
- }
2580
- function FromProperties11(args, properties) {
2581
- return globalThis.Object.getOwnPropertyNames(properties).reduce((result, key) => {
2582
- return { ...result, [key]: FromProperty2(args, properties[key]) };
2583
- }, {});
2584
- }
2585
- function FromTypes(args, types) {
2586
- return types.map((type) => FromType(args, type));
2587
- }
2588
- function FromType(args, type) {
2589
- return IsConstructor(type) ? FromConstructor2(args, type) : IsFunction2(type) ? FromFunction2(args, type) : IsIntersect(type) ? FromIntersect5(args, type) : IsUnion(type) ? FromUnion7(args, type) : IsTuple(type) ? FromTuple4(args, type) : IsArray3(type) ? FromArray5(args, type) : IsAsyncIterator2(type) ? FromAsyncIterator2(args, type) : IsIterator2(type) ? FromIterator2(args, type) : IsPromise(type) ? FromPromise3(args, type) : IsObject3(type) ? FromObject2(args, type) : IsRecord(type) ? FromRecord2(args, type) : IsArgument(type) ? FromArgument(args, type) : type;
2590
- }
2591
- function Instantiate(type, args) {
2592
- return FromType(args, CloneType(type));
2593
- }
2594
-
2595
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/integer/integer.mjs
2596
- function Integer(options) {
2597
- return CreateType({ [Kind]: "Integer", type: "integer" }, options);
2598
- }
2599
-
2600
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/intrinsic/intrinsic-from-mapped-key.mjs
2601
- function MappedIntrinsicPropertyKey(K, M, options) {
2602
- return {
2603
- [K]: Intrinsic(Literal(K), M, Clone(options))
2604
- };
2605
- }
2606
- function MappedIntrinsicPropertyKeys(K, M, options) {
2607
- const result = K.reduce((Acc, L) => {
2608
- return { ...Acc, ...MappedIntrinsicPropertyKey(L, M, options) };
2609
- }, {});
2610
- return result;
2611
- }
2612
- function MappedIntrinsicProperties(T, M, options) {
2613
- return MappedIntrinsicPropertyKeys(T["keys"], M, options);
2614
- }
2615
- function IntrinsicFromMappedKey(T, M, options) {
2616
- const P = MappedIntrinsicProperties(T, M, options);
2617
- return MappedResult(P);
2618
- }
2619
-
2620
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/intrinsic/intrinsic.mjs
2621
- function ApplyUncapitalize(value) {
2622
- const [first, rest] = [value.slice(0, 1), value.slice(1)];
2623
- return [first.toLowerCase(), rest].join("");
2624
- }
2625
- function ApplyCapitalize(value) {
2626
- const [first, rest] = [value.slice(0, 1), value.slice(1)];
2627
- return [first.toUpperCase(), rest].join("");
2628
- }
2629
- function ApplyUppercase(value) {
2630
- return value.toUpperCase();
2631
- }
2632
- function ApplyLowercase(value) {
2633
- return value.toLowerCase();
2634
- }
2635
- function FromTemplateLiteral3(schema, mode, options) {
2636
- const expression = TemplateLiteralParseExact(schema.pattern);
2637
- const finite = IsTemplateLiteralExpressionFinite(expression);
2638
- if (!finite)
2639
- return { ...schema, pattern: FromLiteralValue(schema.pattern, mode) };
2640
- const strings = [...TemplateLiteralExpressionGenerate(expression)];
2641
- const literals = strings.map((value) => Literal(value));
2642
- const mapped = FromRest5(literals, mode);
2643
- const union = Union(mapped);
2644
- return TemplateLiteral([union], options);
2645
- }
2646
- function FromLiteralValue(value, mode) {
2647
- return typeof value === "string" ? mode === "Uncapitalize" ? ApplyUncapitalize(value) : mode === "Capitalize" ? ApplyCapitalize(value) : mode === "Uppercase" ? ApplyUppercase(value) : mode === "Lowercase" ? ApplyLowercase(value) : value : value.toString();
2648
- }
2649
- function FromRest5(T, M) {
2650
- return T.map((L) => Intrinsic(L, M));
2651
- }
2652
- function Intrinsic(schema, mode, options = {}) {
2653
- return (
2654
- // Intrinsic-Mapped-Inference
2655
- IsMappedKey(schema) ? IntrinsicFromMappedKey(schema, mode, options) : (
2656
- // Standard-Inference
2657
- IsTemplateLiteral(schema) ? FromTemplateLiteral3(schema, mode, options) : IsUnion(schema) ? Union(FromRest5(schema.anyOf, mode), options) : IsLiteral(schema) ? Literal(FromLiteralValue(schema.const, mode), options) : (
2658
- // Default Type
2659
- CreateType(schema, options)
2660
- )
2661
- )
2662
- );
2663
- }
2664
-
2665
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/intrinsic/capitalize.mjs
2666
- function Capitalize(T, options = {}) {
2667
- return Intrinsic(T, "Capitalize", options);
2668
- }
2669
-
2670
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/intrinsic/lowercase.mjs
2671
- function Lowercase(T, options = {}) {
2672
- return Intrinsic(T, "Lowercase", options);
2673
- }
2674
-
2675
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/intrinsic/uncapitalize.mjs
2676
- function Uncapitalize(T, options = {}) {
2677
- return Intrinsic(T, "Uncapitalize", options);
2678
- }
2679
-
2680
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/intrinsic/uppercase.mjs
2681
- function Uppercase(T, options = {}) {
2682
- return Intrinsic(T, "Uppercase", options);
2683
- }
2684
-
2685
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/omit/omit-from-mapped-result.mjs
2686
- function FromProperties12(properties, propertyKeys, options) {
2687
- const result = {};
2688
- for (const K2 of globalThis.Object.getOwnPropertyNames(properties))
2689
- result[K2] = Omit(properties[K2], propertyKeys, Clone(options));
2690
- return result;
2691
- }
2692
- function FromMappedResult9(mappedResult, propertyKeys, options) {
2693
- return FromProperties12(mappedResult.properties, propertyKeys, options);
2694
- }
2695
- function OmitFromMappedResult(mappedResult, propertyKeys, options) {
2696
- const properties = FromMappedResult9(mappedResult, propertyKeys, options);
2697
- return MappedResult(properties);
2698
- }
2699
-
2700
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/omit/omit.mjs
2701
- function FromIntersect6(types, propertyKeys) {
2702
- return types.map((type) => OmitResolve(type, propertyKeys));
2703
- }
2704
- function FromUnion8(types, propertyKeys) {
2705
- return types.map((type) => OmitResolve(type, propertyKeys));
2706
- }
2707
- function FromProperty3(properties, key) {
2708
- const { [key]: _, ...R } = properties;
2709
- return R;
2710
- }
2711
- function FromProperties13(properties, propertyKeys) {
2712
- return propertyKeys.reduce((T, K2) => FromProperty3(T, K2), properties);
2713
- }
2714
- function FromObject3(properties, propertyKeys) {
2715
- const options = Discard(properties, [TransformKind, "$id", "required", "properties"]);
2716
- const omittedProperties = FromProperties13(properties["properties"], propertyKeys);
2717
- return Object2(omittedProperties, options);
2718
- }
2719
- function UnionFromPropertyKeys(propertyKeys) {
2720
- const result = propertyKeys.reduce((result2, key) => IsLiteralValue(key) ? [...result2, Literal(key)] : result2, []);
2721
- return Union(result);
2722
- }
2723
- function OmitResolve(properties, propertyKeys) {
2724
- return IsIntersect(properties) ? Intersect(FromIntersect6(properties.allOf, propertyKeys)) : IsUnion(properties) ? Union(FromUnion8(properties.anyOf, propertyKeys)) : IsObject3(properties) ? FromObject3(properties, propertyKeys) : Object2({});
2725
- }
2726
- function Omit(type, key, options) {
2727
- const typeKey = IsArray(key) ? UnionFromPropertyKeys(key) : key;
2728
- const propertyKeys = IsSchema(key) ? IndexPropertyKeys(key) : key;
2729
- const isTypeRef = IsRef(type);
2730
- const isKeyRef = IsRef(key);
2731
- return IsMappedResult(type) ? OmitFromMappedResult(type, propertyKeys, options) : IsMappedKey(key) ? OmitFromMappedKey(type, key, options) : isTypeRef && isKeyRef ? Computed("Omit", [type, typeKey], options) : !isTypeRef && isKeyRef ? Computed("Omit", [type, typeKey], options) : isTypeRef && !isKeyRef ? Computed("Omit", [type, typeKey], options) : CreateType({ ...OmitResolve(type, propertyKeys), ...options });
2732
- }
2733
-
2734
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/omit/omit-from-mapped-key.mjs
2735
- function FromPropertyKey2(type, key, options) {
2736
- return { [key]: Omit(type, [key], Clone(options)) };
2737
- }
2738
- function FromPropertyKeys2(type, propertyKeys, options) {
2739
- return propertyKeys.reduce((Acc, LK) => {
2740
- return { ...Acc, ...FromPropertyKey2(type, LK, options) };
2741
- }, {});
2742
- }
2743
- function FromMappedKey3(type, mappedKey, options) {
2744
- return FromPropertyKeys2(type, mappedKey.keys, options);
2745
- }
2746
- function OmitFromMappedKey(type, mappedKey, options) {
2747
- const properties = FromMappedKey3(type, mappedKey, options);
2748
- return MappedResult(properties);
2749
- }
2750
-
2751
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/pick/pick-from-mapped-result.mjs
2752
- function FromProperties14(properties, propertyKeys, options) {
2753
- const result = {};
2754
- for (const K2 of globalThis.Object.getOwnPropertyNames(properties))
2755
- result[K2] = Pick(properties[K2], propertyKeys, Clone(options));
2756
- return result;
2757
- }
2758
- function FromMappedResult10(mappedResult, propertyKeys, options) {
2759
- return FromProperties14(mappedResult.properties, propertyKeys, options);
2760
- }
2761
- function PickFromMappedResult(mappedResult, propertyKeys, options) {
2762
- const properties = FromMappedResult10(mappedResult, propertyKeys, options);
2763
- return MappedResult(properties);
2764
- }
2765
-
2766
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/pick/pick.mjs
2767
- function FromIntersect7(types, propertyKeys) {
2768
- return types.map((type) => PickResolve(type, propertyKeys));
2769
- }
2770
- function FromUnion9(types, propertyKeys) {
2771
- return types.map((type) => PickResolve(type, propertyKeys));
2772
- }
2773
- function FromProperties15(properties, propertyKeys) {
2774
- const result = {};
2775
- for (const K2 of propertyKeys)
2776
- if (K2 in properties)
2777
- result[K2] = properties[K2];
2778
- return result;
2779
- }
2780
- function FromObject4(T, K) {
2781
- const options = Discard(T, [TransformKind, "$id", "required", "properties"]);
2782
- const properties = FromProperties15(T["properties"], K);
2783
- return Object2(properties, options);
2784
- }
2785
- function UnionFromPropertyKeys2(propertyKeys) {
2786
- const result = propertyKeys.reduce((result2, key) => IsLiteralValue(key) ? [...result2, Literal(key)] : result2, []);
2787
- return Union(result);
2788
- }
2789
- function PickResolve(properties, propertyKeys) {
2790
- return IsIntersect(properties) ? Intersect(FromIntersect7(properties.allOf, propertyKeys)) : IsUnion(properties) ? Union(FromUnion9(properties.anyOf, propertyKeys)) : IsObject3(properties) ? FromObject4(properties, propertyKeys) : Object2({});
2791
- }
2792
- function Pick(type, key, options) {
2793
- const typeKey = IsArray(key) ? UnionFromPropertyKeys2(key) : key;
2794
- const propertyKeys = IsSchema(key) ? IndexPropertyKeys(key) : key;
2795
- const isTypeRef = IsRef(type);
2796
- const isKeyRef = IsRef(key);
2797
- return IsMappedResult(type) ? PickFromMappedResult(type, propertyKeys, options) : IsMappedKey(key) ? PickFromMappedKey(type, key, options) : isTypeRef && isKeyRef ? Computed("Pick", [type, typeKey], options) : !isTypeRef && isKeyRef ? Computed("Pick", [type, typeKey], options) : isTypeRef && !isKeyRef ? Computed("Pick", [type, typeKey], options) : CreateType({ ...PickResolve(type, propertyKeys), ...options });
2798
- }
2799
-
2800
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/pick/pick-from-mapped-key.mjs
2801
- function FromPropertyKey3(type, key, options) {
2802
- return {
2803
- [key]: Pick(type, [key], Clone(options))
2804
- };
2805
- }
2806
- function FromPropertyKeys3(type, propertyKeys, options) {
2807
- return propertyKeys.reduce((result, leftKey) => {
2808
- return { ...result, ...FromPropertyKey3(type, leftKey, options) };
2809
- }, {});
2810
- }
2811
- function FromMappedKey4(type, mappedKey, options) {
2812
- return FromPropertyKeys3(type, mappedKey.keys, options);
2813
- }
2814
- function PickFromMappedKey(type, mappedKey, options) {
2815
- const properties = FromMappedKey4(type, mappedKey, options);
2816
- return MappedResult(properties);
2817
- }
2818
-
2819
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/partial/partial.mjs
2820
- function FromComputed3(target, parameters) {
2821
- return Computed("Partial", [Computed(target, parameters)]);
2822
- }
2823
- function FromRef3($ref) {
2824
- return Computed("Partial", [Ref($ref)]);
2825
- }
2826
- function FromProperties16(properties) {
2827
- const partialProperties = {};
2828
- for (const K of globalThis.Object.getOwnPropertyNames(properties))
2829
- partialProperties[K] = Optional(properties[K]);
2830
- return partialProperties;
2831
- }
2832
- function FromObject5(type) {
2833
- const options = Discard(type, [TransformKind, "$id", "required", "properties"]);
2834
- const properties = FromProperties16(type["properties"]);
2835
- return Object2(properties, options);
2836
- }
2837
- function FromRest6(types) {
2838
- return types.map((type) => PartialResolve(type));
2839
- }
2840
- function PartialResolve(type) {
2841
- return (
2842
- // Mappable
2843
- IsComputed(type) ? FromComputed3(type.target, type.parameters) : IsRef(type) ? FromRef3(type.$ref) : IsIntersect(type) ? Intersect(FromRest6(type.allOf)) : IsUnion(type) ? Union(FromRest6(type.anyOf)) : IsObject3(type) ? FromObject5(type) : (
2844
- // Intrinsic
2845
- IsBigInt2(type) ? type : IsBoolean2(type) ? type : IsInteger(type) ? type : IsLiteral(type) ? type : IsNull2(type) ? type : IsNumber3(type) ? type : IsString2(type) ? type : IsSymbol2(type) ? type : IsUndefined3(type) ? type : (
2846
- // Passthrough
2847
- Object2({})
2848
- )
2849
- )
2850
- );
2851
- }
2852
- function Partial(type, options) {
2853
- if (IsMappedResult(type)) {
2854
- return PartialFromMappedResult(type, options);
2855
- } else {
2856
- return CreateType({ ...PartialResolve(type), ...options });
2857
- }
2858
- }
2859
-
2860
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/partial/partial-from-mapped-result.mjs
2861
- function FromProperties17(K, options) {
2862
- const Acc = {};
2863
- for (const K2 of globalThis.Object.getOwnPropertyNames(K))
2864
- Acc[K2] = Partial(K[K2], Clone(options));
2865
- return Acc;
2866
- }
2867
- function FromMappedResult11(R, options) {
2868
- return FromProperties17(R.properties, options);
2869
- }
2870
- function PartialFromMappedResult(R, options) {
2871
- const P = FromMappedResult11(R, options);
2872
- return MappedResult(P);
2873
- }
2874
-
2875
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/required/required.mjs
2876
- function FromComputed4(target, parameters) {
2877
- return Computed("Required", [Computed(target, parameters)]);
2878
- }
2879
- function FromRef4($ref) {
2880
- return Computed("Required", [Ref($ref)]);
2881
- }
2882
- function FromProperties18(properties) {
2883
- const requiredProperties = {};
2884
- for (const K of globalThis.Object.getOwnPropertyNames(properties))
2885
- requiredProperties[K] = Discard(properties[K], [OptionalKind]);
2886
- return requiredProperties;
2887
- }
2888
- function FromObject6(type) {
2889
- const options = Discard(type, [TransformKind, "$id", "required", "properties"]);
2890
- const properties = FromProperties18(type["properties"]);
2891
- return Object2(properties, options);
2892
- }
2893
- function FromRest7(types) {
2894
- return types.map((type) => RequiredResolve(type));
2895
- }
2896
- function RequiredResolve(type) {
2897
- return (
2898
- // Mappable
2899
- IsComputed(type) ? FromComputed4(type.target, type.parameters) : IsRef(type) ? FromRef4(type.$ref) : IsIntersect(type) ? Intersect(FromRest7(type.allOf)) : IsUnion(type) ? Union(FromRest7(type.anyOf)) : IsObject3(type) ? FromObject6(type) : (
2900
- // Intrinsic
2901
- IsBigInt2(type) ? type : IsBoolean2(type) ? type : IsInteger(type) ? type : IsLiteral(type) ? type : IsNull2(type) ? type : IsNumber3(type) ? type : IsString2(type) ? type : IsSymbol2(type) ? type : IsUndefined3(type) ? type : (
2902
- // Passthrough
2903
- Object2({})
2904
- )
2905
- )
2906
- );
2907
- }
2908
- function Required(type, options) {
2909
- if (IsMappedResult(type)) {
2910
- return RequiredFromMappedResult(type, options);
2911
- } else {
2912
- return CreateType({ ...RequiredResolve(type), ...options });
2913
- }
2914
- }
2915
-
2916
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/required/required-from-mapped-result.mjs
2917
- function FromProperties19(P, options) {
2918
- const Acc = {};
2919
- for (const K2 of globalThis.Object.getOwnPropertyNames(P))
2920
- Acc[K2] = Required(P[K2], options);
2921
- return Acc;
2922
- }
2923
- function FromMappedResult12(R, options) {
2924
- return FromProperties19(R.properties, options);
2925
- }
2926
- function RequiredFromMappedResult(R, options) {
2927
- const P = FromMappedResult12(R, options);
2928
- return MappedResult(P);
2929
- }
2930
-
2931
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/module/compute.mjs
2932
- function DereferenceParameters(moduleProperties, types) {
2933
- return types.map((type) => {
2934
- return IsRef(type) ? Dereference(moduleProperties, type.$ref) : FromType2(moduleProperties, type);
2935
- });
2936
- }
2937
- function Dereference(moduleProperties, ref) {
2938
- return ref in moduleProperties ? IsRef(moduleProperties[ref]) ? Dereference(moduleProperties, moduleProperties[ref].$ref) : FromType2(moduleProperties, moduleProperties[ref]) : Never();
2939
- }
2940
- function FromAwaited(parameters) {
2941
- return Awaited(parameters[0]);
2942
- }
2943
- function FromIndex(parameters) {
2944
- return Index(parameters[0], parameters[1]);
2945
- }
2946
- function FromKeyOf(parameters) {
2947
- return KeyOf(parameters[0]);
2948
- }
2949
- function FromPartial(parameters) {
2950
- return Partial(parameters[0]);
2951
- }
2952
- function FromOmit(parameters) {
2953
- return Omit(parameters[0], parameters[1]);
2954
- }
2955
- function FromPick(parameters) {
2956
- return Pick(parameters[0], parameters[1]);
2957
- }
2958
- function FromRequired(parameters) {
2959
- return Required(parameters[0]);
2960
- }
2961
- function FromComputed5(moduleProperties, target, parameters) {
2962
- const dereferenced = DereferenceParameters(moduleProperties, parameters);
2963
- return target === "Awaited" ? FromAwaited(dereferenced) : target === "Index" ? FromIndex(dereferenced) : target === "KeyOf" ? FromKeyOf(dereferenced) : target === "Partial" ? FromPartial(dereferenced) : target === "Omit" ? FromOmit(dereferenced) : target === "Pick" ? FromPick(dereferenced) : target === "Required" ? FromRequired(dereferenced) : Never();
2964
- }
2965
- function FromArray6(moduleProperties, type) {
2966
- return Array2(FromType2(moduleProperties, type));
2967
- }
2968
- function FromAsyncIterator3(moduleProperties, type) {
2969
- return AsyncIterator(FromType2(moduleProperties, type));
2970
- }
2971
- function FromConstructor3(moduleProperties, parameters, instanceType) {
2972
- return Constructor(FromTypes2(moduleProperties, parameters), FromType2(moduleProperties, instanceType));
2973
- }
2974
- function FromFunction3(moduleProperties, parameters, returnType) {
2975
- return Function(FromTypes2(moduleProperties, parameters), FromType2(moduleProperties, returnType));
2976
- }
2977
- function FromIntersect8(moduleProperties, types) {
2978
- return Intersect(FromTypes2(moduleProperties, types));
2979
- }
2980
- function FromIterator3(moduleProperties, type) {
2981
- return Iterator(FromType2(moduleProperties, type));
2982
- }
2983
- function FromObject7(moduleProperties, properties) {
2984
- return Object2(globalThis.Object.keys(properties).reduce((result, key) => {
2985
- return { ...result, [key]: FromType2(moduleProperties, properties[key]) };
2986
- }, {}));
2987
- }
2988
- function FromRecord3(moduleProperties, type) {
2989
- const [value, pattern] = [FromType2(moduleProperties, RecordValue2(type)), RecordPattern(type)];
2990
- const result = CloneType(type);
2991
- result.patternProperties[pattern] = value;
2992
- return result;
2993
- }
2994
- function FromTransform(moduleProperties, transform) {
2995
- return IsRef(transform) ? { ...Dereference(moduleProperties, transform.$ref), [TransformKind]: transform[TransformKind] } : transform;
2996
- }
2997
- function FromTuple5(moduleProperties, types) {
2998
- return Tuple(FromTypes2(moduleProperties, types));
2999
- }
3000
- function FromUnion10(moduleProperties, types) {
3001
- return Union(FromTypes2(moduleProperties, types));
3002
- }
3003
- function FromTypes2(moduleProperties, types) {
3004
- return types.map((type) => FromType2(moduleProperties, type));
3005
- }
3006
- function FromType2(moduleProperties, type) {
3007
- return (
3008
- // Modifiers
3009
- IsOptional(type) ? CreateType(FromType2(moduleProperties, Discard(type, [OptionalKind])), type) : IsReadonly(type) ? CreateType(FromType2(moduleProperties, Discard(type, [ReadonlyKind])), type) : (
3010
- // Transform
3011
- IsTransform(type) ? CreateType(FromTransform(moduleProperties, type), type) : (
3012
- // Types
3013
- IsArray3(type) ? CreateType(FromArray6(moduleProperties, type.items), type) : IsAsyncIterator2(type) ? CreateType(FromAsyncIterator3(moduleProperties, type.items), type) : IsComputed(type) ? CreateType(FromComputed5(moduleProperties, type.target, type.parameters)) : IsConstructor(type) ? CreateType(FromConstructor3(moduleProperties, type.parameters, type.returns), type) : IsFunction2(type) ? CreateType(FromFunction3(moduleProperties, type.parameters, type.returns), type) : IsIntersect(type) ? CreateType(FromIntersect8(moduleProperties, type.allOf), type) : IsIterator2(type) ? CreateType(FromIterator3(moduleProperties, type.items), type) : IsObject3(type) ? CreateType(FromObject7(moduleProperties, type.properties), type) : IsRecord(type) ? CreateType(FromRecord3(moduleProperties, type)) : IsTuple(type) ? CreateType(FromTuple5(moduleProperties, type.items || []), type) : IsUnion(type) ? CreateType(FromUnion10(moduleProperties, type.anyOf), type) : type
3014
- )
3015
- )
3016
- );
3017
- }
3018
- function ComputeType(moduleProperties, key) {
3019
- return key in moduleProperties ? FromType2(moduleProperties, moduleProperties[key]) : Never();
3020
- }
3021
- function ComputeModuleProperties(moduleProperties) {
3022
- return globalThis.Object.getOwnPropertyNames(moduleProperties).reduce((result, key) => {
3023
- return { ...result, [key]: ComputeType(moduleProperties, key) };
3024
- }, {});
3025
- }
3026
-
3027
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/module/module.mjs
3028
- var TModule = class {
3029
- constructor($defs) {
3030
- const computed = ComputeModuleProperties($defs);
3031
- const identified = this.WithIdentifiers(computed);
3032
- this.$defs = identified;
3033
- }
3034
- /** `[Json]` Imports a Type by Key. */
3035
- Import(key, options) {
3036
- const $defs = { ...this.$defs, [key]: CreateType(this.$defs[key], options) };
3037
- return CreateType({ [Kind]: "Import", $defs, $ref: key });
3038
- }
3039
- // prettier-ignore
3040
- WithIdentifiers($defs) {
3041
- return globalThis.Object.getOwnPropertyNames($defs).reduce((result, key) => {
3042
- return { ...result, [key]: { ...$defs[key], $id: key } };
3043
- }, {});
3044
- }
3045
- };
3046
- function Module(properties) {
3047
- return new TModule(properties);
3048
- }
3049
-
3050
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/not/not.mjs
3051
- function Not(type, options) {
3052
- return CreateType({ [Kind]: "Not", not: type }, options);
3053
- }
3054
-
3055
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/parameters/parameters.mjs
3056
- function Parameters(schema, options) {
3057
- return IsFunction2(schema) ? Tuple(schema.parameters, options) : Never();
3058
- }
3059
-
3060
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/recursive/recursive.mjs
3061
- var Ordinal = 0;
3062
- function Recursive(callback, options = {}) {
3063
- if (IsUndefined(options.$id))
3064
- options.$id = `T${Ordinal++}`;
3065
- const thisType = CloneType(callback({ [Kind]: "This", $ref: `${options.$id}` }));
3066
- thisType.$id = options.$id;
3067
- return CreateType({ [Hint]: "Recursive", ...thisType }, options);
3068
- }
3069
-
3070
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/regexp/regexp.mjs
3071
- function RegExp2(unresolved, options) {
3072
- const expr = IsString(unresolved) ? new globalThis.RegExp(unresolved) : unresolved;
3073
- return CreateType({ [Kind]: "RegExp", type: "RegExp", source: expr.source, flags: expr.flags }, options);
3074
- }
3075
-
3076
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/rest/rest.mjs
3077
- function RestResolve(T) {
3078
- return IsIntersect(T) ? T.allOf : IsUnion(T) ? T.anyOf : IsTuple(T) ? T.items ?? [] : [];
3079
- }
3080
- function Rest(T) {
3081
- return RestResolve(T);
3082
- }
3083
-
3084
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/return-type/return-type.mjs
3085
- function ReturnType(schema, options) {
3086
- return IsFunction2(schema) ? CreateType(schema.returns, options) : Never(options);
3087
- }
3088
-
3089
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/transform/transform.mjs
3090
- var TransformDecodeBuilder = class {
3091
- constructor(schema) {
3092
- this.schema = schema;
3093
- }
3094
- Decode(decode) {
3095
- return new TransformEncodeBuilder(this.schema, decode);
3096
- }
3097
- };
3098
- var TransformEncodeBuilder = class {
3099
- constructor(schema, decode) {
3100
- this.schema = schema;
3101
- this.decode = decode;
3102
- }
3103
- EncodeTransform(encode, schema) {
3104
- const Encode = (value) => schema[TransformKind].Encode(encode(value));
3105
- const Decode = (value) => this.decode(schema[TransformKind].Decode(value));
3106
- const Codec = { Encode, Decode };
3107
- return { ...schema, [TransformKind]: Codec };
3108
- }
3109
- EncodeSchema(encode, schema) {
3110
- const Codec = { Decode: this.decode, Encode: encode };
3111
- return { ...schema, [TransformKind]: Codec };
3112
- }
3113
- Encode(encode) {
3114
- return IsTransform(this.schema) ? this.EncodeTransform(encode, this.schema) : this.EncodeSchema(encode, this.schema);
3115
- }
3116
- };
3117
- function Transform(schema) {
3118
- return new TransformDecodeBuilder(schema);
3119
- }
3120
-
3121
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/unsafe/unsafe.mjs
3122
- function Unsafe(options = {}) {
3123
- return CreateType({ [Kind]: options[Kind] ?? "Unsafe" }, options);
3124
- }
3125
-
3126
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/void/void.mjs
3127
- function Void(options) {
3128
- return CreateType({ [Kind]: "Void", type: "void" }, options);
3129
- }
3130
-
3131
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/type/type.mjs
3132
- var type_exports2 = {};
3133
- __export(type_exports2, {
3134
- Any: () => Any,
3135
- Argument: () => Argument,
3136
- Array: () => Array2,
3137
- AsyncIterator: () => AsyncIterator,
3138
- Awaited: () => Awaited,
3139
- BigInt: () => BigInt,
3140
- Boolean: () => Boolean,
3141
- Capitalize: () => Capitalize,
3142
- Composite: () => Composite,
3143
- Const: () => Const,
3144
- Constructor: () => Constructor,
3145
- ConstructorParameters: () => ConstructorParameters,
3146
- Date: () => Date2,
3147
- Enum: () => Enum,
3148
- Exclude: () => Exclude,
3149
- Extends: () => Extends,
3150
- Extract: () => Extract,
3151
- Function: () => Function,
3152
- Index: () => Index,
3153
- InstanceType: () => InstanceType,
3154
- Instantiate: () => Instantiate,
3155
- Integer: () => Integer,
3156
- Intersect: () => Intersect,
3157
- Iterator: () => Iterator,
3158
- KeyOf: () => KeyOf,
3159
- Literal: () => Literal,
3160
- Lowercase: () => Lowercase,
3161
- Mapped: () => Mapped,
3162
- Module: () => Module,
3163
- Never: () => Never,
3164
- Not: () => Not,
3165
- Null: () => Null,
3166
- Number: () => Number2,
3167
- Object: () => Object2,
3168
- Omit: () => Omit,
3169
- Optional: () => Optional,
3170
- Parameters: () => Parameters,
3171
- Partial: () => Partial,
3172
- Pick: () => Pick,
3173
- Promise: () => Promise2,
3174
- Readonly: () => Readonly,
3175
- ReadonlyOptional: () => ReadonlyOptional,
3176
- Record: () => Record,
3177
- Recursive: () => Recursive,
3178
- Ref: () => Ref,
3179
- RegExp: () => RegExp2,
3180
- Required: () => Required,
3181
- Rest: () => Rest,
3182
- ReturnType: () => ReturnType,
3183
- String: () => String2,
3184
- Symbol: () => Symbol2,
3185
- TemplateLiteral: () => TemplateLiteral,
3186
- Transform: () => Transform,
3187
- Tuple: () => Tuple,
3188
- Uint8Array: () => Uint8Array2,
3189
- Uncapitalize: () => Uncapitalize,
3190
- Undefined: () => Undefined,
3191
- Union: () => Union,
3192
- Unknown: () => Unknown,
3193
- Unsafe: () => Unsafe,
3194
- Uppercase: () => Uppercase,
3195
- Void: () => Void
3196
- });
3197
-
3198
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/type/index.mjs
3199
- var Type = type_exports2;
3200
-
3201
- // src/lib/types/schemas.ts
3202
- var SuccessResponseSchema = (dataSchema) => Type.Object(
3203
- {
3204
- success: Type.Literal(true),
3205
- data: dataSchema,
3206
- message: Type.Optional(Type.String())
3207
- }
3208
- );
3209
- var ErrorResponseSchema = Type.Object(
3210
- {
3211
- success: Type.Literal(false),
3212
- error: Type.Object(
3213
- {
3214
- code: Type.String(),
3215
- message: Type.String(),
3216
- details: Type.Optional(Type.Any())
3217
- }
3218
- )
3219
- }
3220
- );
3221
- var ApiResponseSchema = (dataSchema) => Type.Union([
3222
- SuccessResponseSchema(dataSchema),
3223
- ErrorResponseSchema
3224
- ]);
3225
-
3226
- // src/lib/contracts/auth.ts
3227
- var EMAIL_PATTERN = "^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$";
3228
- var PHONE_PATTERN = "^\\+[1-9]\\d{1,14}$";
3229
- var FINGERPRINT_PATTERN = "^[a-f0-9]{64}$";
3230
- var UUID_PATTERN = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
3231
- var BASE64_PATTERN = "^[A-Za-z0-9+/]+=*$";
3232
- var sendVerificationCodeContract = {
3233
- method: "POST",
3234
- path: "/_auth/codes",
3235
- body: Type.Object({
3236
- target: Type.String({
3237
- description: "Email address or phone number in E.164 format"
3238
- }),
3239
- targetType: Type.Union([
3240
- Type.Literal("email"),
3241
- Type.Literal("phone")
3242
- ], {
3243
- description: "Type of target (email or phone)"
3244
- }),
3245
- purpose: Type.Union([
3246
- Type.Literal("registration"),
3247
- Type.Literal("login"),
3248
- Type.Literal("password_reset")
3249
- ], {
3250
- description: "Purpose of verification"
3251
- })
3252
- }),
3253
- response: ApiResponseSchema(
3254
- Type.Object({
3255
- success: Type.Boolean(),
3256
- expiresAt: Type.String({ description: "ISO 8601 expiry time" })
3257
- })
3258
- )
3259
- };
3260
- var verifyCodeContract = {
3261
- method: "POST",
3262
- path: "/_auth/codes/verify",
3263
- body: Type.Object({
3264
- target: Type.String({
3265
- description: "Email address or phone number"
3266
- }),
3267
- targetType: Type.Union([
3268
- Type.Literal("email"),
3269
- Type.Literal("phone")
3270
- ]),
3271
- code: Type.String({
3272
- minLength: 6,
3273
- maxLength: 6,
3274
- pattern: "^[0-9]{6}$",
3275
- description: "6-digit verification code"
3276
- }),
3277
- purpose: Type.Union([
3278
- Type.Literal("registration"),
3279
- Type.Literal("login"),
3280
- Type.Literal("password_reset")
3281
- ])
3282
- }),
3283
- response: ApiResponseSchema(
3284
- Type.Object({
3285
- valid: Type.Boolean(),
3286
- verificationToken: Type.Optional(Type.String({
3287
- description: "Temporary token for completing registration (15min validity)"
3288
- }))
3289
- })
3290
- )
3291
- };
3292
- var checkAccountExistsContract = {
3293
- method: "POST",
3294
- path: "/_auth/exists",
3295
- body: Type.Object(
3296
- {
3297
- email: Type.Optional(Type.String({
3298
- pattern: EMAIL_PATTERN,
3299
- description: "Email address to check"
3300
- })),
3301
- phone: Type.Optional(Type.String({
3302
- pattern: PHONE_PATTERN,
3303
- description: "Phone number in E.164 format (e.g., +821012345678)"
3304
- }))
3305
- },
3306
- {
3307
- minProperties: 1,
3308
- description: "At least one of email or phone must be provided"
3309
- }
3310
- ),
3311
- response: ApiResponseSchema(
3312
- Type.Object(
3313
- {
3314
- exists: Type.Boolean({ description: "Whether the account exists" }),
3315
- identifier: Type.String({ description: "The identifier that was checked" }),
3316
- identifierType: Type.Union([
3317
- Type.Literal("email"),
3318
- Type.Literal("phone")
3319
- ], { description: "Type of identifier checked" })
3320
- }
3321
- )
3322
- )
3323
- };
3324
- var registerContract = {
3325
- method: "POST",
3326
- path: "/_auth/register",
3327
- body: Type.Object({
3328
- email: Type.Optional(Type.String({
3329
- pattern: EMAIL_PATTERN,
3330
- description: "Email address"
3331
- })),
3332
- phone: Type.Optional(Type.String({
3333
- pattern: PHONE_PATTERN,
3334
- description: "Phone number in E.164 format"
3335
- })),
3336
- verificationToken: Type.String({
3337
- description: "Verification token obtained from /verify-code endpoint"
3338
- }),
3339
- password: Type.String({
3340
- minLength: 8,
3341
- description: "User password (minimum 8 characters)"
3342
- }),
3343
- publicKey: Type.String({
3344
- pattern: BASE64_PATTERN,
3345
- description: "Base64 encoded DER public key (SPKI format)"
3346
- }),
3347
- keyId: Type.String({
3348
- pattern: UUID_PATTERN,
3349
- description: "Client-generated UUID v4 key identifier"
3350
- }),
3351
- fingerprint: Type.String({
3352
- pattern: FINGERPRINT_PATTERN,
3353
- description: "SHA-256 fingerprint of public key (64 hex characters)"
3354
- }),
3355
- algorithm: Type.Union([
3356
- Type.Literal("ES256"),
3357
- Type.Literal("RS256")
3358
- ], {
3359
- description: "Signing algorithm (ES256 recommended, RS256 for compatibility)"
3360
- }),
3361
- keySize: Type.Optional(Type.Number({
3362
- description: "Key size in bytes"
3363
- }))
3364
- }, {
3365
- minProperties: 6,
3366
- // email/phone + verificationToken + password + publicKey + keyId + fingerprint
3367
- description: "Email or phone must be provided with verification token"
3368
- }),
3369
- response: ApiResponseSchema(
3370
- Type.Object({
3371
- userId: Type.String(),
3372
- email: Type.Optional(Type.String()),
3373
- phone: Type.Optional(Type.String())
3374
- })
3375
- )
3376
- };
3377
- var loginContract = {
3378
- method: "POST",
3379
- path: "/_auth/login",
3380
- body: Type.Object({
3381
- email: Type.Optional(Type.String({
3382
- pattern: EMAIL_PATTERN,
3383
- description: "Email address"
3384
- })),
3385
- phone: Type.Optional(Type.String({
3386
- pattern: PHONE_PATTERN,
3387
- description: "Phone number in E.164 format"
3388
- })),
3389
- password: Type.String({
3390
- minLength: 1,
3391
- description: "User password"
3392
- }),
3393
- publicKey: Type.String({
3394
- pattern: BASE64_PATTERN,
3395
- description: "Base64 encoded DER public key (SPKI format)"
3396
- }),
3397
- keyId: Type.String({
3398
- pattern: UUID_PATTERN,
3399
- description: "Client-generated UUID v4 key identifier"
3400
- }),
3401
- fingerprint: Type.String({
3402
- pattern: FINGERPRINT_PATTERN,
3403
- description: "SHA-256 fingerprint of public key (64 hex characters)"
3404
- }),
3405
- oldKeyId: Type.Optional(Type.String({
3406
- pattern: UUID_PATTERN,
3407
- description: "Previous key ID to revoke (server-side cleanup)"
3408
- })),
3409
- algorithm: Type.Union([
3410
- Type.Literal("ES256"),
3411
- Type.Literal("RS256")
3412
- ], {
3413
- description: "Signing algorithm (ES256 recommended, RS256 for compatibility)"
3414
- }),
3415
- keySize: Type.Optional(Type.Number({
3416
- description: "Key size in bytes"
3417
- }))
3418
- }, {
3419
- minProperties: 5,
3420
- // email/phone + password + publicKey + keyId + fingerprint
3421
- description: "Email or phone must be provided along with key data"
3422
- }),
3423
- response: ApiResponseSchema(
3424
- Type.Object({
3425
- userId: Type.String(),
3426
- email: Type.Optional(Type.String()),
3427
- phone: Type.Optional(Type.String()),
3428
- passwordChangeRequired: Type.Boolean({
3429
- description: "Whether user must change password before proceeding"
3430
- })
3431
- })
3432
- )
3433
- };
3434
- var logoutContract = {
3435
- method: "POST",
3436
- path: "/_auth/logout",
3437
- body: Type.Object({}),
3438
- response: ApiResponseSchema(
3439
- Type.Object({
3440
- success: Type.Boolean()
3441
- })
3442
- )
3443
- };
3444
- var rotateKeyContract = {
3445
- method: "POST",
3446
- path: "/_auth/keys/rotate",
3447
- body: Type.Object({
3448
- publicKey: Type.String({
3449
- pattern: BASE64_PATTERN,
3450
- description: "Base64 encoded DER public key (SPKI format)"
3451
- }),
3452
- keyId: Type.String({
3453
- pattern: UUID_PATTERN,
3454
- description: "Client-generated UUID v4 key identifier"
3455
- }),
3456
- fingerprint: Type.String({
3457
- pattern: FINGERPRINT_PATTERN,
3458
- description: "SHA-256 fingerprint of public key (64 hex characters)"
3459
- }),
3460
- algorithm: Type.Union([
3461
- Type.Literal("ES256"),
3462
- Type.Literal("RS256")
3463
- ], {
3464
- description: "Signing algorithm (ES256 recommended, RS256 for compatibility)"
3465
- }),
3466
- keySize: Type.Optional(Type.Number({
3467
- description: "Key size in bytes"
3468
- }))
3469
- }),
3470
- response: ApiResponseSchema(
3471
- Type.Object({
3472
- success: Type.Boolean(),
3473
- keyId: Type.String()
3474
- })
3475
- )
3476
- };
3477
- var changePasswordContract = {
3478
- method: "PUT",
3479
- path: "/_auth/password",
3480
- body: Type.Object({
3481
- currentPassword: Type.String({
3482
- minLength: 1,
3483
- description: "Current password for verification"
3484
- }),
3485
- newPassword: Type.String({
3486
- minLength: 8,
3487
- description: "New password (minimum 8 characters)"
3488
- })
3489
- }),
3490
- response: ApiResponseSchema(
3491
- Type.Object({
3492
- success: Type.Boolean({ description: "Whether password was changed successfully" })
3493
- })
3494
- )
3495
- };
3496
- var getMeContract = {
3497
- method: "GET",
3498
- path: "/_auth/me",
3499
- body: Type.Object({}),
3500
- response: ApiResponseSchema(
3501
- Type.Object({
3502
- userId: Type.String({ description: "User ID" }),
3503
- email: Type.Optional(Type.String({ description: "User email address" })),
3504
- phone: Type.Optional(Type.String({ description: "User phone number" })),
3505
- role: Type.Object({
3506
- id: Type.Number({ description: "Role ID" }),
3507
- name: Type.String({ description: "Role name (e.g., user, admin)" }),
3508
- displayName: Type.String({ description: "Display name for UI" }),
3509
- priority: Type.Number({ description: "Role priority level" })
3510
- }, { description: "User role information" }),
3511
- permissions: Type.Array(
3512
- Type.Object({
3513
- id: Type.Number({ description: "Permission ID" }),
3514
- name: Type.String({ description: "Permission name (e.g., user:delete)" }),
3515
- displayName: Type.String({ description: "Display name for UI" }),
3516
- category: Type.Optional(Type.String({ description: "Permission category" }))
3517
- }),
3518
- { description: "List of permissions granted through role" }
3519
- )
3520
- })
3521
- )
3522
- };
3523
-
3524
- // src/lib/contracts/invitation.ts
3525
- var UUID_PATTERN2 = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
3526
- var EMAIL_PATTERN2 = "^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$";
3527
- var BASE64_PATTERN2 = "^[A-Za-z0-9+/]+=*$";
3528
- var FINGERPRINT_PATTERN2 = "^[a-f0-9]{64}$";
3529
- var getInvitationContract = {
3530
- method: "GET",
3531
- path: "/_auth/invitations/:token",
3532
- params: Type.Object({
3533
- token: Type.String({
3534
- pattern: UUID_PATTERN2,
3535
- description: "Invitation token (UUID v4)"
3536
- })
3537
- }),
3538
- response: ApiResponseSchema(
3539
- Type.Object({
3540
- email: Type.String({
3541
- format: "email",
3542
- description: "Email address being invited"
3543
- }),
3544
- role: Type.String({
3545
- description: 'Role name (e.g., "admin", "user")'
3546
- }),
3547
- roleDisplayName: Type.String({
3548
- description: 'Role display name (e.g., "Administrator")'
3549
- }),
3550
- invitedBy: Type.String({
3551
- format: "email",
3552
- description: "Email of user who sent invitation"
3553
- }),
3554
- expiresAt: Type.String({
3555
- format: "date-time",
3556
- description: "ISO 8601 expiration timestamp"
3557
- }),
3558
- metadata: Type.Optional(Type.Any({
3559
- description: "Custom metadata (welcome message, etc.)"
3560
- }))
3561
- })
3562
- )
3563
- };
3564
- var acceptInvitationContract = {
3565
- method: "POST",
3566
- path: "/_auth/invitations/accept",
3567
- body: Type.Object({
3568
- token: Type.String({
3569
- pattern: UUID_PATTERN2,
3570
- description: "Invitation token"
3571
- }),
3572
- password: Type.String({
3573
- minLength: 8,
3574
- description: "Account password (minimum 8 characters)"
3575
- }),
3576
- publicKey: Type.String({
3577
- pattern: BASE64_PATTERN2,
3578
- description: "Base64 DER encoded public key (SPKI format)"
3579
- }),
3580
- keyId: Type.String({
3581
- pattern: UUID_PATTERN2,
3582
- description: "Unique key identifier (UUID v4)"
3583
- }),
3584
- fingerprint: Type.String({
3585
- pattern: FINGERPRINT_PATTERN2,
3586
- description: "SHA-256 fingerprint of public key (64 hex chars)"
3587
- }),
3588
- algorithm: Type.Union([
3589
- Type.Literal("ES256"),
3590
- Type.Literal("RS256")
3591
- ], {
3592
- description: "Asymmetric signing algorithm"
3593
- })
3594
- }),
3595
- response: ApiResponseSchema(
3596
- Type.Object({
3597
- userId: Type.Number({
3598
- description: "Created user ID"
3599
- }),
3600
- email: Type.String({
3601
- format: "email",
3602
- description: "User email address"
3603
- }),
3604
- role: Type.String({
3605
- description: "Assigned role name"
3606
- })
3607
- })
3608
- )
3609
- };
3610
- var createInvitationContract = {
3611
- method: "POST",
3612
- path: "/_auth/invitations",
3613
- body: Type.Object({
3614
- email: Type.String({
3615
- pattern: EMAIL_PATTERN2,
3616
- description: "Email address to invite"
3617
- }),
3618
- roleId: Type.Number({
3619
- description: "Role ID to assign"
3620
- }),
3621
- expiresInDays: Type.Optional(Type.Number({
3622
- minimum: 1,
3623
- maximum: 30,
3624
- description: "Days until invitation expires (default: 7)"
3625
- })),
3626
- metadata: Type.Optional(Type.Any({
3627
- description: "Custom metadata (welcome message, department, etc.)"
3628
- }))
3629
- }),
3630
- response: ApiResponseSchema(
3631
- Type.Object({
3632
- id: Type.Number(),
3633
- email: Type.String({ format: "email" }),
3634
- token: Type.String({
3635
- description: "Invitation token (send via email)"
3636
- }),
3637
- roleId: Type.Number(),
3638
- expiresAt: Type.String({
3639
- format: "date-time",
3640
- description: "ISO 8601 expiration timestamp"
3641
- }),
3642
- invitationUrl: Type.String({
3643
- description: "Full invitation URL for email"
3644
- })
3645
- })
3646
- )
3647
- };
3648
- var listInvitationsContract = {
3649
- method: "GET",
3650
- path: "/_auth/invitations",
3651
- query: Type.Object({
3652
- status: Type.Optional(Type.Union([
3653
- Type.Literal("pending"),
3654
- Type.Literal("accepted"),
3655
- Type.Literal("expired"),
3656
- Type.Literal("cancelled")
3657
- ], {
3658
- description: "Filter by status"
3659
- })),
3660
- page: Type.Optional(Type.Number({
3661
- minimum: 1,
3662
- description: "Page number (default: 1)"
3663
- })),
3664
- limit: Type.Optional(Type.Number({
3665
- minimum: 1,
3666
- maximum: 100,
3667
- description: "Items per page (default: 20)"
3668
- }))
3669
- }),
3670
- response: ApiResponseSchema(
3671
- Type.Object({
3672
- invitations: Type.Array(Type.Object({
3673
- id: Type.Number(),
3674
- email: Type.String({ format: "email" }),
3675
- status: Type.String(),
3676
- role: Type.Object({
3677
- id: Type.Number(),
3678
- name: Type.String(),
3679
- displayName: Type.String()
3680
- }),
3681
- inviter: Type.Object({
3682
- id: Type.Number(),
3683
- email: Type.String({ format: "email" })
3684
- }),
3685
- createdAt: Type.String({ format: "date-time" }),
3686
- expiresAt: Type.String({ format: "date-time" }),
3687
- acceptedAt: Type.Optional(Type.String({ format: "date-time" })),
3688
- cancelledAt: Type.Optional(Type.String({ format: "date-time" }))
3689
- })),
3690
- total: Type.Number({ description: "Total invitation count" }),
3691
- page: Type.Number({ description: "Current page" }),
3692
- limit: Type.Number({ description: "Items per page" }),
3693
- totalPages: Type.Number({ description: "Total page count" })
3694
- })
3695
- )
3696
- };
3697
- var cancelInvitationContract = {
3698
- method: "POST",
3699
- path: "/_auth/invitations/cancel",
3700
- body: Type.Object({
3701
- id: Type.Number({
3702
- description: "Invitation ID"
3703
- }),
3704
- reason: Type.Optional(Type.String({
3705
- description: "Cancellation reason"
3706
- }))
3707
- }),
3708
- response: ApiResponseSchema(
3709
- Type.Object({
3710
- success: Type.Boolean(),
3711
- cancelledAt: Type.String({
3712
- format: "date-time",
3713
- description: "Cancellation timestamp"
3714
- })
3715
- })
3716
- )
3717
- };
3718
- var resendInvitationContract = {
3719
- method: "POST",
3720
- path: "/_auth/invitations/resend",
3721
- body: Type.Object({
3722
- id: Type.Number({
3723
- description: "Invitation ID"
3724
- }),
3725
- expiresInDays: Type.Optional(Type.Number({
3726
- minimum: 1,
3727
- maximum: 30,
3728
- description: "New expiration period (default: 7)"
3729
- }))
3730
- }),
3731
- response: ApiResponseSchema(
3732
- Type.Object({
3733
- success: Type.Boolean(),
3734
- expiresAt: Type.String({
3735
- format: "date-time",
3736
- description: "New expiration timestamp"
3737
- })
3738
- })
3739
- )
3740
- };
3741
- var deleteInvitationContract = {
3742
- method: "POST",
3743
- path: "/_auth/invitations/delete",
3744
- body: Type.Object({
3745
- id: Type.Number({
3746
- description: "Invitation ID"
3747
- })
3748
- }),
3749
- response: ApiResponseSchema(
3750
- Type.Object({
3751
- success: Type.Boolean()
3752
- })
3753
- )
3754
- };
3755
-
3756
- // src/server/middleware/authenticate.ts
3757
- init_jwt();
3758
- init_entities();
3759
- import { findOne, getDatabase } from "@spfn/core/db";
3760
-
3761
- // src/server/errors/auth-errors.ts
3762
- import {
3763
- ValidationError,
3764
- UnauthorizedError,
3765
- ForbiddenError,
3766
- ConflictError
3767
- } from "@spfn/core/errors";
3768
- var InvalidTokenError = class extends UnauthorizedError {
3769
- constructor(message = "Invalid authentication token") {
3770
- super(message);
3771
- this.name = "InvalidTokenError";
3772
- }
3773
- };
3774
- var TokenExpiredError = class extends UnauthorizedError {
3775
- constructor(message = "Authentication token has expired") {
3776
- super(message);
3777
- this.name = "TokenExpiredError";
3778
- }
3779
- };
3780
- var KeyExpiredError = class extends UnauthorizedError {
3781
- constructor(message = "Public key has expired") {
3782
- super(message);
3783
- this.name = "KeyExpiredError";
3784
- }
3785
- };
3786
- var AccountDisabledError = class extends ForbiddenError {
3787
- constructor(status = "disabled") {
3788
- super(`Account is ${status}`, { details: { status } });
3789
- this.name = "AccountDisabledError";
3790
- }
3791
- };
3792
-
3793
- // src/server/middleware/authenticate.ts
3794
- import { UnauthorizedError as UnauthorizedError2 } from "@spfn/core/errors";
3795
- import { eq, and } from "drizzle-orm";
3796
- async function authenticate(c, next) {
3797
- const authHeader = c.req.header("Authorization");
3798
- if (!authHeader || !authHeader.startsWith("Bearer ")) {
3799
- throw new UnauthorizedError2("Missing or invalid authorization header");
3800
- }
3801
- const token = authHeader.substring(7);
3802
- const { decodeToken: decodeToken2 } = await Promise.resolve().then(() => (init_jwt(), jwt_exports));
3803
- const decoded = decodeToken2(token);
3804
- if (!decoded || !decoded.keyId) {
3805
- throw new UnauthorizedError2("Invalid token: missing keyId");
3806
- }
3807
- const keyId = decoded.keyId;
3808
- const db = getDatabase();
3809
- const [keyRecord] = await db.select().from(userPublicKeys).where(
3810
- and(
3811
- eq(userPublicKeys.keyId, keyId),
3812
- eq(userPublicKeys.isActive, true)
3813
- )
3814
- );
3815
- if (!keyRecord) {
3816
- throw new UnauthorizedError2("Invalid or revoked key");
3817
- }
3818
- if (keyRecord.expiresAt && /* @__PURE__ */ new Date() > keyRecord.expiresAt) {
3819
- throw new KeyExpiredError();
3820
- }
3821
- try {
3822
- verifyClientToken(
3823
- token,
3824
- keyRecord.publicKey,
3825
- keyRecord.algorithm
3826
- );
3827
- } catch (err) {
3828
- if (err instanceof Error) {
3829
- if (err.name === "TokenExpiredError") {
3830
- throw new TokenExpiredError();
3831
- }
3832
- if (err.name === "JsonWebTokenError") {
3833
- throw new InvalidTokenError("Invalid token signature");
3834
- }
3835
- }
3836
- throw new UnauthorizedError2("Authentication failed");
3837
- }
3838
- const user = await findOne(users, { id: keyRecord.userId });
3839
- if (!user) {
3840
- throw new UnauthorizedError2("User not found");
3841
- }
3842
- if (user.status !== "active") {
3843
- throw new AccountDisabledError(user.status);
3844
- }
3845
- db.update(userPublicKeys).set({ lastUsedAt: /* @__PURE__ */ new Date() }).where(eq(userPublicKeys.id, keyRecord.id)).execute().catch((err) => console.error("Failed to update lastUsedAt:", err));
3846
- c.set("auth", {
3847
- user,
3848
- userId: String(user.id),
3849
- keyId
3850
- });
3851
- await next();
3852
- }
3853
-
3854
- // src/server/helpers/context.ts
3855
- function getAuth(c) {
3856
- if ("raw" in c && c.raw) {
3857
- return c.raw.get("auth");
3858
- }
3859
- return c.get("auth");
3860
- }
3861
-
3862
- // src/server/services/permission.service.ts
3863
- init_entities();
3864
- import { getDatabase as getDatabase2 } from "@spfn/core/db";
3865
- import { eq as eq2, and as and2 } from "drizzle-orm";
3866
- async function getUserPermissions(userId) {
3867
- const db = getDatabase2();
3868
- if (!db) {
3869
- throw new Error("[Auth] Database not initialized");
3870
- }
3871
- const userIdNum = typeof userId === "string" ? Number(userId) : Number(userId);
3872
- const [user] = await db.select({ roleId: users.roleId }).from(users).where(eq2(users.id, userIdNum)).limit(1);
3873
- if (!user || !user.roleId) {
3874
- return [];
3875
- }
3876
- const permSet = /* @__PURE__ */ new Set();
3877
- const rolePerms = await db.select({ name: permissions.name }).from(rolePermissions).innerJoin(permissions, eq2(rolePermissions.permissionId, permissions.id)).where(
3878
- and2(
3879
- eq2(rolePermissions.roleId, user.roleId),
3880
- eq2(permissions.isActive, true)
3881
- )
3882
- );
3883
- for (const perm of rolePerms) {
3884
- permSet.add(perm.name);
3885
- }
3886
- const userPerms = await db.select({
3887
- name: permissions.name,
3888
- granted: userPermissions.granted,
3889
- expiresAt: userPermissions.expiresAt
3890
- }).from(userPermissions).innerJoin(permissions, eq2(userPermissions.permissionId, permissions.id)).where(eq2(userPermissions.userId, userIdNum));
3891
- const now = /* @__PURE__ */ new Date();
3892
- for (const userPerm of userPerms) {
3893
- if (userPerm.expiresAt && userPerm.expiresAt < now) {
3894
- continue;
3895
- }
3896
- if (userPerm.granted) {
3897
- permSet.add(userPerm.name);
3898
- } else {
3899
- permSet.delete(userPerm.name);
3900
- }
3901
- }
3902
- return Array.from(permSet);
3903
- }
3904
- async function hasAllPermissions(userId, permissionNames) {
3905
- const perms = await getUserPermissions(userId);
3906
- return permissionNames.every((p) => perms.includes(p));
3907
- }
3908
- async function hasRole(userId, roleName) {
3909
- const db = getDatabase2();
3910
- if (!db) {
3911
- throw new Error("[Auth] Database not initialized");
3912
- }
3913
- const userIdNum = typeof userId === "string" ? Number(userId) : Number(userId);
3914
- const [user] = await db.select({ roleId: users.roleId }).from(users).where(eq2(users.id, userIdNum)).limit(1);
3915
- if (!user || !user.roleId) {
3916
- return false;
3917
- }
3918
- const [role] = await db.select({ name: roles.name }).from(roles).where(eq2(roles.id, user.roleId)).limit(1);
3919
- return role?.name === roleName;
3920
- }
3921
- async function hasAnyRole(userId, roleNames) {
3922
- for (const roleName of roleNames) {
3923
- if (await hasRole(userId, roleName)) {
3924
- return true;
3925
- }
3926
- }
3927
- return false;
3928
- }
3929
-
3930
- // src/server/middleware/require-permission.ts
3931
- import { ForbiddenError as ForbiddenError2 } from "@spfn/core/errors";
3932
- function requirePermissions(...permissionNames) {
3933
- return async (c, next) => {
3934
- const auth = getAuth(c);
3935
- if (!auth) {
3936
- throw new ForbiddenError2("Authentication required");
3937
- }
3938
- const { userId } = auth;
3939
- const allowed = await hasAllPermissions(userId, permissionNames);
3940
- if (!allowed) {
3941
- throw new ForbiddenError2(
3942
- `Missing required permissions: ${permissionNames.join(", ")}`
3943
- );
3944
- }
3945
- await next();
3946
- };
3947
- }
3948
-
3949
- // src/server/middleware/require-role.ts
3950
- import { ForbiddenError as ForbiddenError3 } from "@spfn/core/errors";
3951
- function requireRole(...roleNames) {
3952
- return async (c, next) => {
3953
- const auth = getAuth(c);
3954
- if (!auth) {
3955
- throw new ForbiddenError3("Authentication required");
3956
- }
3957
- const { userId } = auth;
3958
- const allowed = await hasAnyRole(userId, roleNames);
3959
- if (!allowed) {
3960
- throw new ForbiddenError3(
3961
- `Required roles: ${roleNames.join(", ")}`
3962
- );
3963
- }
3964
- await next();
3965
- };
3966
- }
3967
-
3968
- // src/server/helpers/password.ts
3969
- import bcrypt from "bcrypt";
3970
- var SALT_ROUNDS = parseInt(
3971
- process.env.SPFN_AUTH_BCRYPT_SALT_ROUNDS || // New prefixed version (recommended)
3972
- process.env.BCRYPT_SALT_ROUNDS || // Legacy fallback
3973
- "10",
3974
- 10
3975
- );
3976
- async function hashPassword(password) {
3977
- if (!password || password.length === 0) {
3978
- throw new Error("Password cannot be empty");
3979
- }
3980
- return bcrypt.hash(password, SALT_ROUNDS);
3981
- }
3982
-
3983
- // src/server/helpers/index.ts
3984
- init_jwt();
3985
-
3986
- // src/server/helpers/verification.ts
3987
- init_verification_codes();
3988
- import jwt2 from "jsonwebtoken";
3989
- import { getDatabase as getDatabase3, create } from "@spfn/core/db";
3990
- import { eq as eq3, and as and3 } from "drizzle-orm";
3991
-
3992
- // src/server/services/auth.service.ts
3993
- init_entities();
3994
- import { findOne as findOne3, create as create3 } from "@spfn/core/db";
3995
- import { ValidationError as ValidationError2 } from "@spfn/core/errors";
3996
-
3997
- // src/server/services/key.service.ts
3998
- init_entities();
3999
- init_jwt();
4000
- import { create as create2, getDatabase as getDatabase4 } from "@spfn/core/db";
4001
- import { eq as eq4, and as and4 } from "drizzle-orm";
4002
-
4003
- // src/server/services/user.service.ts
4004
- init_entities();
4005
- import { findOne as findOne2, updateOne } from "@spfn/core/db";
4006
-
4007
- // src/server/services/me.service.ts
4008
- init_entities();
4009
- import { getDatabase as getDatabase5 } from "@spfn/core/db";
4010
- import { eq as eq5, and as and5 } from "drizzle-orm";
4011
-
4012
- // src/server/services/rbac.service.ts
4013
- init_entities();
4014
- import { getDatabase as getDatabase6 } from "@spfn/core/db";
4015
- import { logger } from "@spfn/core/logger";
4016
- import { eq as eq6, and as and6, inArray } from "drizzle-orm";
4017
- var authLogger = logger.child("@spfn/auth");
4018
-
4019
- // src/server/services/index.ts
4020
- init_role_service();
4021
-
4022
- // src/server/services/invitation.service.ts
4023
- init_entities();
4024
- import { getDatabase as getDatabase8 } from "@spfn/core/db";
4025
- import { eq as eq8, and as and8, lt, desc, sql as sql2 } from "drizzle-orm";
4026
- import crypto2 from "crypto";
4027
- function generateInvitationToken() {
4028
- return crypto2.randomUUID();
4029
- }
4030
- function calculateExpiresAt(days = 7) {
4031
- const expiresAt = /* @__PURE__ */ new Date();
4032
- expiresAt.setDate(expiresAt.getDate() + days);
4033
- return expiresAt;
4034
- }
4035
- async function createInvitation(params) {
4036
- const db = getDatabase8();
4037
- if (!db) {
4038
- throw new Error("[Auth] Database not initialized");
4039
- }
4040
- const { email, roleId, invitedBy, expiresInDays = 7, metadata } = params;
4041
- const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
4042
- if (!emailRegex.test(email)) {
4043
- throw new Error("Invalid email format");
4044
- }
4045
- const existingUser = await db.select().from(users).where(eq8(users.email, email)).limit(1);
4046
- if (existingUser.length > 0) {
4047
- throw new Error("User with this email already exists");
4048
- }
4049
- const existingInvitation = await db.select().from(invitations).where(
4050
- and8(
4051
- eq8(invitations.email, email),
4052
- eq8(invitations.status, "pending")
4053
- )
4054
- ).limit(1);
4055
- if (existingInvitation.length > 0) {
4056
- throw new Error("Pending invitation already exists for this email");
4057
- }
4058
- const role = await db.select().from(roles).where(eq8(roles.id, roleId)).limit(1);
4059
- if (role.length === 0) {
4060
- throw new Error(`Role with id ${roleId} not found`);
4061
- }
4062
- const inviter = await db.select().from(users).where(eq8(users.id, invitedBy)).limit(1);
4063
- if (inviter.length === 0) {
4064
- throw new Error(`User with id ${invitedBy} not found`);
4065
- }
4066
- const token = generateInvitationToken();
4067
- const expiresAt = calculateExpiresAt(expiresInDays);
4068
- const [invitation] = await db.insert(invitations).values({
4069
- email,
4070
- token,
4071
- roleId,
4072
- invitedBy,
4073
- status: "pending",
4074
- expiresAt,
4075
- metadata: metadata || null
4076
- }).returning();
4077
- console.log(`[Auth] \u2705 Created invitation: ${email} as ${role[0].name} (expires: ${expiresAt.toISOString()})`);
4078
- return invitation;
4079
- }
4080
- async function getInvitationByToken(token) {
4081
- const db = getDatabase8();
4082
- if (!db) {
4083
- throw new Error("[Auth] Database not initialized");
4084
- }
4085
- const result = await db.select().from(invitations).where(eq8(invitations.token, token)).limit(1);
4086
- return result[0] || null;
4087
- }
4088
- async function getInvitationWithDetails(token) {
4089
- const db = getDatabase8();
4090
- if (!db) {
4091
- throw new Error("[Auth] Database not initialized");
4092
- }
4093
- const result = await db.select({
4094
- id: invitations.id,
4095
- email: invitations.email,
4096
- token: invitations.token,
4097
- roleId: invitations.roleId,
4098
- invitedBy: invitations.invitedBy,
4099
- status: invitations.status,
4100
- expiresAt: invitations.expiresAt,
4101
- acceptedAt: invitations.acceptedAt,
4102
- cancelledAt: invitations.cancelledAt,
4103
- metadata: invitations.metadata,
4104
- createdAt: invitations.createdAt,
4105
- updatedAt: invitations.updatedAt,
4106
- role: {
4107
- id: roles.id,
4108
- name: roles.name,
4109
- displayName: roles.displayName
4110
- },
4111
- inviter: {
4112
- id: users.id,
4113
- email: users.email
4114
- }
4115
- }).from(invitations).innerJoin(roles, eq8(invitations.roleId, roles.id)).innerJoin(users, eq8(invitations.invitedBy, users.id)).where(eq8(invitations.token, token)).limit(1);
4116
- return result[0] || null;
4117
- }
4118
- async function validateInvitation(token) {
4119
- const invitation = await getInvitationByToken(token);
4120
- if (!invitation) {
4121
- return { valid: false, error: "Invitation not found" };
4122
- }
4123
- if (invitation.status === "accepted") {
4124
- return { valid: false, error: "Invitation already accepted", invitation };
4125
- }
4126
- if (invitation.status === "cancelled") {
4127
- return { valid: false, error: "Invitation was cancelled", invitation };
4128
- }
4129
- if (invitation.status === "expired") {
4130
- return { valid: false, error: "Invitation has expired", invitation };
4131
- }
4132
- if (/* @__PURE__ */ new Date() > new Date(invitation.expiresAt)) {
4133
- return { valid: false, error: "Invitation has expired", invitation };
4134
- }
4135
- return { valid: true, invitation };
4136
- }
4137
- async function acceptInvitation(params) {
4138
- const db = getDatabase8();
4139
- if (!db) {
4140
- throw new Error("[Auth] Database not initialized");
4141
- }
4142
- const { token, password, publicKey, keyId, fingerprint, algorithm } = params;
4143
- const validation = await validateInvitation(token);
4144
- if (!validation.valid || !validation.invitation) {
4145
- throw new Error(validation.error || "Invalid invitation");
4146
- }
4147
- const invitation = validation.invitation;
4148
- const role = await db.select().from(roles).where(eq8(roles.id, invitation.roleId)).limit(1);
4149
- if (role.length === 0) {
4150
- throw new Error("Role not found");
4151
- }
4152
- const passwordHash = await hashPassword(password);
4153
- const result = await db.transaction(async (tx) => {
4154
- const [newUser] = await tx.insert(users).values({
4155
- email: invitation.email,
4156
- passwordHash,
4157
- roleId: invitation.roleId,
4158
- emailVerifiedAt: /* @__PURE__ */ new Date(),
4159
- // Auto-verify invited users
4160
- passwordChangeRequired: false,
4161
- status: "active"
4162
- }).returning();
4163
- const { userPublicKeys: userPublicKeys2 } = await Promise.resolve().then(() => (init_entities(), entities_exports));
4164
- await tx.insert(userPublicKeys2).values({
4165
- userId: newUser.id,
4166
- keyId,
4167
- publicKey,
4168
- algorithm,
4169
- fingerprint,
4170
- isActive: true,
4171
- expiresAt: new Date(Date.now() + 90 * 24 * 60 * 60 * 1e3)
4172
- // 90 days
4173
- });
4174
- await tx.update(invitations).set({
4175
- status: "accepted",
4176
- acceptedAt: /* @__PURE__ */ new Date(),
4177
- updatedAt: /* @__PURE__ */ new Date()
4178
- }).where(eq8(invitations.id, invitation.id));
4179
- return { newUser, role: role[0] };
4180
- });
4181
- console.log(`[Auth] \u2705 Invitation accepted: ${invitation.email} as ${result.role.name}`);
4182
- return {
4183
- userId: result.newUser.id,
4184
- email: result.newUser.email,
4185
- role: result.role.name
4186
- };
4187
- }
4188
- async function listInvitations(params) {
4189
- const db = getDatabase8();
4190
- if (!db) {
4191
- throw new Error("[Auth] Database not initialized");
4192
- }
4193
- const { status, invitedBy, page = 1, limit = 20 } = params;
4194
- const offset = (page - 1) * limit;
4195
- const conditions = [];
4196
- if (status) {
4197
- conditions.push(eq8(invitations.status, status));
4198
- }
4199
- if (invitedBy) {
4200
- conditions.push(eq8(invitations.invitedBy, invitedBy));
4201
- }
4202
- const whereClause = conditions.length > 0 ? and8(...conditions) : void 0;
4203
- const countResult = await db.select({ count: sql2`count(*)` }).from(invitations).where(whereClause);
4204
- const total = Number(countResult[0]?.count || 0);
4205
- const results = await db.select({
4206
- id: invitations.id,
4207
- email: invitations.email,
4208
- token: invitations.token,
4209
- roleId: invitations.roleId,
4210
- invitedBy: invitations.invitedBy,
4211
- status: invitations.status,
4212
- expiresAt: invitations.expiresAt,
4213
- acceptedAt: invitations.acceptedAt,
4214
- cancelledAt: invitations.cancelledAt,
4215
- metadata: invitations.metadata,
4216
- createdAt: invitations.createdAt,
4217
- updatedAt: invitations.updatedAt,
4218
- role: {
4219
- id: roles.id,
4220
- name: roles.name,
4221
- displayName: roles.displayName
4222
- },
4223
- inviter: {
4224
- id: users.id,
4225
- email: users.email
4226
- }
4227
- }).from(invitations).innerJoin(roles, eq8(invitations.roleId, roles.id)).innerJoin(users, eq8(invitations.invitedBy, users.id)).where(whereClause).orderBy(desc(invitations.createdAt)).limit(limit).offset(offset);
4228
- return {
4229
- invitations: results,
4230
- total,
4231
- page,
4232
- limit,
4233
- totalPages: Math.ceil(total / limit)
4234
- };
4235
- }
4236
- async function cancelInvitation(id10, cancelledBy, reason) {
4237
- const db = getDatabase8();
4238
- if (!db) {
4239
- throw new Error("[Auth] Database not initialized");
4240
- }
4241
- const invitation = await db.select().from(invitations).where(eq8(invitations.id, id10)).limit(1);
4242
- if (invitation.length === 0) {
4243
- throw new Error("Invitation not found");
4244
- }
4245
- if (invitation[0].status !== "pending") {
4246
- throw new Error(`Cannot cancel ${invitation[0].status} invitation`);
4247
- }
4248
- await db.update(invitations).set({
4249
- status: "cancelled",
4250
- cancelledAt: /* @__PURE__ */ new Date(),
4251
- updatedAt: /* @__PURE__ */ new Date(),
4252
- metadata: invitation[0].metadata ? { ...invitation[0].metadata, cancelReason: reason, cancelledBy } : { cancelReason: reason, cancelledBy }
4253
- }).where(eq8(invitations.id, id10));
4254
- console.log(`[Auth] \u26A0\uFE0F Invitation cancelled: ${invitation[0].email} (reason: ${reason || "none"})`);
4255
- }
4256
- async function deleteInvitation(id10) {
4257
- const db = getDatabase8();
4258
- if (!db) {
4259
- throw new Error("[Auth] Database not initialized");
4260
- }
4261
- await db.delete(invitations).where(eq8(invitations.id, id10));
4262
- console.log(`[Auth] \u{1F5D1}\uFE0F Invitation deleted: ${id10}`);
4263
- }
4264
- async function resendInvitation(id10, expiresInDays = 7) {
4265
- const db = getDatabase8();
4266
- if (!db) {
4267
- throw new Error("[Auth] Database not initialized");
4268
- }
4269
- const invitation = await db.select().from(invitations).where(eq8(invitations.id, id10)).limit(1);
4270
- if (invitation.length === 0) {
4271
- throw new Error("Invitation not found");
4272
- }
4273
- if (!["pending", "expired"].includes(invitation[0].status)) {
4274
- throw new Error(`Cannot resend ${invitation[0].status} invitation`);
4275
- }
4276
- const newExpiresAt = calculateExpiresAt(expiresInDays);
4277
- const [updated] = await db.update(invitations).set({
4278
- status: "pending",
4279
- expiresAt: newExpiresAt,
4280
- updatedAt: /* @__PURE__ */ new Date()
4281
- }).where(eq8(invitations.id, id10)).returning();
4282
- console.log(`[Auth] \u{1F4E7} Invitation resent: ${invitation[0].email} (new expiry: ${newExpiresAt.toISOString()})`);
4283
- return updated;
4284
- }
4285
-
4286
- // src/server/routes/invitations/index.ts
4287
- var app = createApp();
4288
- app.bind(getInvitationContract, async (c) => {
4289
- const params = await c.data();
4290
- const token = params.token;
4291
- const validation = await validateInvitation(token);
4292
- if (!validation.valid || !validation.invitation) {
4293
- throw new Error(validation.error || "Invalid invitation");
4294
- }
4295
- const invitation = await getInvitationWithDetails(token);
4296
- if (!invitation) {
4297
- throw new Error("Invitation not found");
4298
- }
4299
- return c.success({
4300
- email: invitation.email,
4301
- role: invitation.role.name,
4302
- roleDisplayName: invitation.role.displayName,
4303
- invitedBy: invitation.inviter.email || "Unknown",
4304
- expiresAt: invitation.expiresAt.toISOString(),
4305
- metadata: invitation.metadata || void 0
4306
- });
4307
- });
4308
- app.bind(acceptInvitationContract, async (c) => {
4309
- const body = await c.data();
4310
- const result = await acceptInvitation({
4311
- token: body.token,
4312
- password: body.password,
4313
- publicKey: body.publicKey,
4314
- keyId: body.keyId,
4315
- fingerprint: body.fingerprint,
4316
- algorithm: body.algorithm
4317
- });
4318
- return c.success(result);
4319
- });
4320
- app.bind(createInvitationContract, [authenticate, requirePermissions("user:invite")], async (c) => {
4321
- const body = await c.data();
4322
- const { userId } = getAuth(c);
4323
- const invitation = await createInvitation({
4324
- email: body.email,
4325
- roleId: body.roleId,
4326
- invitedBy: Number(userId),
4327
- expiresInDays: body.expiresInDays,
4328
- metadata: body.metadata
4329
- });
4330
- const baseUrl = process.env.SPFN_API_URL || "http://localhost:8790";
4331
- const invitationUrl = `${baseUrl}/auth/invite/${invitation.token}`;
4332
- return c.success({
4333
- id: invitation.id,
4334
- email: invitation.email,
4335
- token: invitation.token,
4336
- roleId: invitation.roleId,
4337
- expiresAt: invitation.expiresAt.toISOString(),
4338
- invitationUrl
4339
- });
4340
- });
4341
- app.bind(listInvitationsContract, [authenticate, requirePermissions("user:read")], async (c) => {
4342
- const query = await c.data();
4343
- const result = await listInvitations({
4344
- status: query.status,
4345
- page: query.page ? Number(query.page) : void 0,
4346
- limit: query.limit ? Number(query.limit) : void 0
4347
- });
4348
- const formattedInvitations = result.invitations.map((inv) => ({
4349
- ...inv,
4350
- createdAt: inv.createdAt.toISOString(),
4351
- expiresAt: inv.expiresAt.toISOString(),
4352
- acceptedAt: inv.acceptedAt ? inv.acceptedAt.toISOString() : void 0,
4353
- cancelledAt: inv.cancelledAt ? inv.cancelledAt.toISOString() : void 0
4354
- }));
4355
- return c.success({
4356
- ...result,
4357
- invitations: formattedInvitations
4358
- });
4359
- });
4360
- app.bind(cancelInvitationContract, [authenticate, requirePermissions("user:invite")], async (c) => {
4361
- const data = await c.data();
4362
- const { userId } = getAuth(c);
4363
- await cancelInvitation(
4364
- data.id,
4365
- Number(userId),
4366
- data.reason
4367
- );
4368
- return c.success({
4369
- success: true,
4370
- cancelledAt: (/* @__PURE__ */ new Date()).toISOString()
4371
- });
4372
- });
4373
- app.bind(resendInvitationContract, [authenticate, requirePermissions("user:invite")], async (c) => {
4374
- const data = await c.data();
4375
- const updated = await resendInvitation(
4376
- data.id,
4377
- data.expiresInDays
4378
- );
4379
- return c.success({
4380
- success: true,
4381
- expiresAt: updated.expiresAt.toISOString()
4382
- });
4383
- });
4384
- app.bind(deleteInvitationContract, [authenticate, requireRole("superadmin")], async (c) => {
4385
- const data = await c.data();
4386
- await deleteInvitation(data.id);
4387
- return c.success({
4388
- success: true
4389
- });
4390
- });
4391
- var invitations_default = app;
4392
- export {
4393
- invitations_default as default
4394
- };
4395
- //# sourceMappingURL=index.js.map