@spfn/auth 0.1.0-alpha.87 → 0.2.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/README.md +1385 -1199
  2. package/dist/config.d.ts +405 -0
  3. package/dist/config.js +240 -0
  4. package/dist/config.js.map +1 -0
  5. package/dist/dto-81uR9gzF.d.ts +630 -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 +273 -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 +179 -0
  16. package/dist/nextjs/server.js.map +1 -0
  17. package/dist/server.d.ts +4328 -529
  18. package/dist/server.js +7841 -1247
  19. package/dist/server.js.map +1 -1
  20. package/migrations/{0000_familiar_firebrand.sql → 0000_mysterious_colossus.sql} +53 -23
  21. package/migrations/meta/0000_snapshot.json +281 -46
  22. package/migrations/meta/_journal.json +2 -2
  23. package/package.json +33 -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/dist/{lib.d.ts → nextjs/api.d.ts} +0 -0
@@ -1,3645 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __export = (target, all) => {
3
- for (var name in all)
4
- __defProp(target, name, { get: all[name], enumerable: true });
5
- };
6
-
7
- // src/adapters/nextjs/server.ts
8
- import "server-only";
9
-
10
- // src/adapters/nextjs/interceptors/index.ts
11
- import { registerInterceptors } from "@spfn/core/client/nextjs";
12
-
13
- // src/adapters/nextjs/interceptors/login-register.ts
14
- import { logger } from "@spfn/core/logger";
15
-
16
- // src/lib/crypto.ts
17
- import crypto2 from "crypto";
18
- import jwt from "jsonwebtoken";
19
- function generateKeyPairES256() {
20
- const keyId = crypto2.randomUUID();
21
- const { privateKey, publicKey } = crypto2.generateKeyPairSync("ec", {
22
- namedCurve: "P-256",
23
- // ES256
24
- publicKeyEncoding: {
25
- type: "spki",
26
- format: "der"
27
- },
28
- privateKeyEncoding: {
29
- type: "pkcs8",
30
- format: "der"
31
- }
32
- });
33
- const privateKeyB64 = privateKey.toString("base64");
34
- const publicKeyB64 = publicKey.toString("base64");
35
- const fingerprint = crypto2.createHash("sha256").update(publicKey).digest("hex");
36
- return {
37
- privateKey: privateKeyB64,
38
- publicKey: publicKeyB64,
39
- keyId,
40
- fingerprint,
41
- algorithm: "ES256"
42
- };
43
- }
44
- function generateKeyPairRS256() {
45
- const keyId = crypto2.randomUUID();
46
- const { privateKey, publicKey } = crypto2.generateKeyPairSync("rsa", {
47
- modulusLength: 2048,
48
- publicKeyEncoding: {
49
- type: "spki",
50
- format: "der"
51
- },
52
- privateKeyEncoding: {
53
- type: "pkcs8",
54
- format: "der"
55
- }
56
- });
57
- const privateKeyB64 = privateKey.toString("base64");
58
- const publicKeyB64 = publicKey.toString("base64");
59
- const fingerprint = crypto2.createHash("sha256").update(publicKey).digest("hex");
60
- return {
61
- privateKey: privateKeyB64,
62
- publicKey: publicKeyB64,
63
- keyId,
64
- fingerprint,
65
- algorithm: "RS256"
66
- };
67
- }
68
- function generateKeyPair(algorithm = "ES256") {
69
- return algorithm === "ES256" ? generateKeyPairES256() : generateKeyPairRS256();
70
- }
71
- function generateClientToken(payload, privateKeyB64, algorithm, options) {
72
- try {
73
- const privateKeyDER = Buffer.from(privateKeyB64, "base64");
74
- const privateKeyObject = crypto2.createPrivateKey({
75
- key: privateKeyDER,
76
- format: "der",
77
- type: "pkcs8"
78
- });
79
- const privateKeyPEM = privateKeyObject.export({
80
- type: "pkcs8",
81
- format: "pem"
82
- });
83
- const signOptions = {
84
- algorithm,
85
- issuer: options?.issuer || "spfn-client",
86
- expiresIn: options?.expiresIn ?? "15m"
87
- // Default to 15 minutes
88
- };
89
- return jwt.sign(payload, privateKeyPEM, signOptions);
90
- } catch (error) {
91
- throw new Error(
92
- `Failed to generate client token: ${error instanceof Error ? error.message : "Unknown error"}`
93
- );
94
- }
95
- }
96
-
97
- // src/lib/session.ts
98
- import * as jose from "jose";
99
- async function getSessionSecret() {
100
- const secret = process.env.SPFN_AUTH_SESSION_SECRET || // New prefixed version (recommended)
101
- process.env.SESSION_SECRET;
102
- if (!secret) {
103
- throw new Error("SPFN_AUTH_SESSION_SECRET environment variable is not set");
104
- }
105
- if (secret.length < 32) {
106
- throw new Error("SPFN_AUTH_SESSION_SECRET must be at least 32 characters long");
107
- }
108
- const encoder = new TextEncoder();
109
- const data = encoder.encode(secret);
110
- const hashBuffer = await crypto.subtle.digest("SHA-256", data);
111
- return new Uint8Array(hashBuffer);
112
- }
113
- async function sealSession(data, ttl = 60 * 60 * 24 * 7) {
114
- const secret = await getSessionSecret();
115
- return await new jose.EncryptJWT({ data }).setProtectedHeader({ alg: "dir", enc: "A256GCM" }).setIssuedAt().setExpirationTime(`${ttl}s`).setIssuer("spfn-auth").setAudience("spfn-client").encrypt(secret);
116
- }
117
- async function unsealSession(jwt2) {
118
- const secret = await getSessionSecret();
119
- try {
120
- const { payload } = await jose.jwtDecrypt(jwt2, secret, {
121
- issuer: "spfn-auth",
122
- audience: "spfn-client"
123
- });
124
- return payload.data;
125
- } catch (err) {
126
- if (err instanceof jose.errors.JWTExpired) {
127
- throw new Error("Session expired");
128
- }
129
- if (err instanceof jose.errors.JWEDecryptionFailed) {
130
- throw new Error("Invalid session");
131
- }
132
- if (err instanceof jose.errors.JWTClaimValidationFailed) {
133
- throw new Error("Session validation failed");
134
- }
135
- throw new Error("Failed to unseal session");
136
- }
137
- }
138
- async function getSessionInfo(jwt2) {
139
- const secret = await getSessionSecret();
140
- try {
141
- const { payload } = await jose.jwtDecrypt(jwt2, secret);
142
- return {
143
- issuedAt: new Date(payload.iat * 1e3),
144
- expiresAt: new Date(payload.exp * 1e3),
145
- issuer: payload.iss || "",
146
- audience: Array.isArray(payload.aud) ? payload.aud[0] : payload.aud || ""
147
- };
148
- } catch (err) {
149
- if (process.env.NODE_ENV !== "production") {
150
- console.warn("[Session] Failed to get session info:", err instanceof Error ? err.message : "Unknown error");
151
- }
152
- return null;
153
- }
154
- }
155
- async function shouldRefreshSession(jwt2, thresholdHours = 24) {
156
- const info = await getSessionInfo(jwt2);
157
- if (!info) {
158
- return true;
159
- }
160
- const hoursRemaining = (info.expiresAt.getTime() - Date.now()) / (1e3 * 60 * 60);
161
- return hoursRemaining < thresholdHours;
162
- }
163
-
164
- // src/lib/config.ts
165
- var COOKIE_NAMES = {
166
- /** Encrypted session data (userId, privateKey, keyId, algorithm) */
167
- SESSION: "spfn_session",
168
- /** Current key ID (for key rotation) */
169
- SESSION_KEY_ID: "spfn_session_key_id"
170
- };
171
- function parseDuration(duration) {
172
- if (typeof duration === "number") {
173
- return duration;
174
- }
175
- const match = duration.match(/^(\d+)([dhms]?)$/);
176
- if (!match) {
177
- throw new Error(`Invalid duration format: ${duration}. Use format like '30d', '12h', '45m', '3600s', or plain number.`);
178
- }
179
- const value = parseInt(match[1], 10);
180
- const unit = match[2] || "s";
181
- switch (unit) {
182
- case "d":
183
- return value * 24 * 60 * 60;
184
- case "h":
185
- return value * 60 * 60;
186
- case "m":
187
- return value * 60;
188
- case "s":
189
- return value;
190
- default:
191
- throw new Error(`Unknown duration unit: ${unit}`);
192
- }
193
- }
194
- var globalConfig = {
195
- sessionTtl: "7d"
196
- // Default: 7 days
197
- };
198
- function getSessionTtl(override) {
199
- if (override !== void 0) {
200
- return parseDuration(override);
201
- }
202
- if (globalConfig.sessionTtl !== void 0) {
203
- return parseDuration(globalConfig.sessionTtl);
204
- }
205
- const envTtl = process.env.SPFN_AUTH_SESSION_TTL;
206
- if (envTtl) {
207
- return parseDuration(envTtl);
208
- }
209
- return 7 * 24 * 60 * 60;
210
- }
211
-
212
- // src/adapters/nextjs/interceptors/login-register.ts
213
- var authLogger = logger.child("auth:interceptor:login-register");
214
- var loginRegisterInterceptor = {
215
- pathPattern: /^\/_auth\/(login|register)$/,
216
- method: "POST",
217
- request: async (ctx, next) => {
218
- const oldKeyId = ctx.cookies.get(COOKIE_NAMES.SESSION_KEY_ID);
219
- const remember = ctx.body?.remember;
220
- const keyPair = generateKeyPair("ES256");
221
- if (!ctx.body) {
222
- ctx.body = {};
223
- }
224
- ctx.body.publicKey = keyPair.publicKey;
225
- ctx.body.keyId = keyPair.keyId;
226
- ctx.body.fingerprint = keyPair.fingerprint;
227
- ctx.body.algorithm = keyPair.algorithm;
228
- ctx.body.keySize = Buffer.from(keyPair.publicKey, "base64").length;
229
- if (ctx.path === "/_auth/login" && oldKeyId) {
230
- ctx.body.oldKeyId = oldKeyId;
231
- }
232
- delete ctx.body.remember;
233
- ctx.metadata.privateKey = keyPair.privateKey;
234
- ctx.metadata.keyId = keyPair.keyId;
235
- ctx.metadata.algorithm = keyPair.algorithm;
236
- ctx.metadata.remember = remember;
237
- await next();
238
- },
239
- response: async (ctx, next) => {
240
- if (ctx.response.status !== 200) {
241
- await next();
242
- return;
243
- }
244
- const { data } = ctx.response.body;
245
- if (!data?.userId) {
246
- authLogger.error("No userId in response");
247
- await next();
248
- return;
249
- }
250
- try {
251
- const ttl = getSessionTtl(ctx.metadata.remember);
252
- const sessionData = {
253
- userId: data.userId,
254
- privateKey: ctx.metadata.privateKey,
255
- keyId: ctx.metadata.keyId,
256
- algorithm: ctx.metadata.algorithm
257
- };
258
- const sealed = await sealSession(sessionData, ttl);
259
- ctx.setCookies.push({
260
- name: COOKIE_NAMES.SESSION,
261
- value: sealed,
262
- options: {
263
- httpOnly: true,
264
- secure: process.env.NODE_ENV === "production",
265
- sameSite: "strict",
266
- maxAge: ttl,
267
- path: "/"
268
- }
269
- });
270
- ctx.setCookies.push({
271
- name: COOKIE_NAMES.SESSION_KEY_ID,
272
- value: ctx.metadata.keyId,
273
- options: {
274
- httpOnly: true,
275
- secure: process.env.NODE_ENV === "production",
276
- sameSite: "strict",
277
- maxAge: ttl,
278
- path: "/"
279
- }
280
- });
281
- } catch (error) {
282
- const err = error;
283
- authLogger.error("Failed to save session", err);
284
- }
285
- await next();
286
- }
287
- };
288
-
289
- // src/adapters/nextjs/interceptors/general-auth.ts
290
- import { logger as logger2 } from "@spfn/core/logger";
291
- var authLogger2 = logger2.child("auth:interceptor:general");
292
- function requiresAuth(path) {
293
- const publicPaths = [
294
- /^\/_auth\/login$/,
295
- /^\/_auth\/register$/,
296
- /^\/_auth\/codes$/,
297
- // Send verification code
298
- /^\/_auth\/codes\/verify$/,
299
- // Verify code
300
- /^\/_auth\/exists$/
301
- // Check account exists
302
- ];
303
- return !publicPaths.some((pattern) => pattern.test(path));
304
- }
305
- var generalAuthInterceptor = {
306
- pathPattern: /^\/_auth\//,
307
- method: ["GET", "POST", "PUT", "PATCH", "DELETE"],
308
- request: async (ctx, next) => {
309
- if (!requiresAuth(ctx.path)) {
310
- authLogger2.debug(`Public path, skipping auth: ${ctx.path}`);
311
- await next();
312
- return;
313
- }
314
- const sessionCookie = ctx.cookies.get(COOKIE_NAMES.SESSION);
315
- authLogger2.debug("Request", {
316
- method: ctx.method,
317
- path: ctx.path,
318
- hasSession: !!sessionCookie
319
- });
320
- if (!sessionCookie) {
321
- authLogger2.debug("No session cookie, proceeding without auth");
322
- await next();
323
- return;
324
- }
325
- try {
326
- const session = await unsealSession(sessionCookie);
327
- authLogger2.debug("Session valid", {
328
- userId: session.userId,
329
- keyId: session.keyId
330
- });
331
- const needsRefresh = await shouldRefreshSession(sessionCookie, 24);
332
- if (needsRefresh) {
333
- authLogger2.debug("Session needs refresh (within 24h of expiry)");
334
- ctx.metadata.refreshSession = true;
335
- ctx.metadata.sessionData = session;
336
- }
337
- const token = await generateClientToken(
338
- {
339
- userId: session.userId,
340
- keyId: session.keyId,
341
- timestamp: Date.now()
342
- },
343
- session.privateKey,
344
- session.algorithm,
345
- { expiresIn: "15m" }
346
- );
347
- authLogger2.debug("Generated JWT token (expires in 15m)");
348
- ctx.headers["Authorization"] = `Bearer ${token}`;
349
- ctx.headers["X-Key-Id"] = session.keyId;
350
- ctx.metadata.userId = session.userId;
351
- ctx.metadata.sessionValid = true;
352
- } catch (error) {
353
- const err = error;
354
- if (err.message.includes("expired") || err.message.includes("invalid")) {
355
- authLogger2.warn("Session expired or invalid", { message: err.message });
356
- authLogger2.debug("Marking session for cleanup");
357
- ctx.metadata.clearSession = true;
358
- ctx.metadata.sessionValid = false;
359
- } else {
360
- authLogger2.error("Failed to process session", err);
361
- }
362
- }
363
- await next();
364
- },
365
- response: async (ctx, next) => {
366
- if (ctx.metadata.clearSession) {
367
- ctx.setCookies.push({
368
- name: COOKIE_NAMES.SESSION,
369
- value: "",
370
- options: {
371
- maxAge: 0,
372
- path: "/"
373
- }
374
- });
375
- ctx.setCookies.push({
376
- name: COOKIE_NAMES.SESSION_KEY_ID,
377
- value: "",
378
- options: {
379
- maxAge: 0,
380
- path: "/"
381
- }
382
- });
383
- } else if (ctx.metadata.refreshSession && ctx.response.status === 200) {
384
- try {
385
- const sessionData = ctx.metadata.sessionData;
386
- const ttl = getSessionTtl();
387
- const sealed = await sealSession(sessionData, ttl);
388
- ctx.setCookies.push({
389
- name: COOKIE_NAMES.SESSION,
390
- value: sealed,
391
- options: {
392
- httpOnly: true,
393
- secure: process.env.NODE_ENV === "production",
394
- sameSite: "strict",
395
- maxAge: ttl,
396
- path: "/"
397
- }
398
- });
399
- ctx.setCookies.push({
400
- name: COOKIE_NAMES.SESSION_KEY_ID,
401
- value: sessionData.keyId,
402
- options: {
403
- httpOnly: true,
404
- secure: process.env.NODE_ENV === "production",
405
- sameSite: "strict",
406
- maxAge: ttl,
407
- path: "/"
408
- }
409
- });
410
- authLogger2.info("Session refreshed", { userId: sessionData.userId });
411
- } catch (error) {
412
- const err = error;
413
- authLogger2.error("Failed to refresh session", err);
414
- }
415
- } else if (ctx.path === "/_auth/logout" && ctx.response.status === 200) {
416
- ctx.setCookies.push({
417
- name: COOKIE_NAMES.SESSION,
418
- value: "",
419
- options: {
420
- maxAge: 0,
421
- path: "/"
422
- }
423
- });
424
- ctx.setCookies.push({
425
- name: COOKIE_NAMES.SESSION_KEY_ID,
426
- value: "",
427
- options: {
428
- maxAge: 0,
429
- path: "/"
430
- }
431
- });
432
- }
433
- await next();
434
- }
435
- };
436
-
437
- // src/adapters/nextjs/interceptors/key-rotation.ts
438
- import { logger as logger3 } from "@spfn/core/logger";
439
- var authLogger3 = logger3.child("auth:interceptor:key-rotation");
440
- var keyRotationInterceptor = {
441
- pathPattern: "/_auth/keys/rotate",
442
- method: "POST",
443
- request: async (ctx, next) => {
444
- const sessionCookie = ctx.cookies.get(COOKIE_NAMES.SESSION);
445
- if (!sessionCookie) {
446
- await next();
447
- return;
448
- }
449
- try {
450
- const currentSession = await unsealSession(sessionCookie);
451
- const newKeyPair = generateKeyPair("ES256");
452
- if (!ctx.body) {
453
- ctx.body = {};
454
- }
455
- ctx.body.publicKey = newKeyPair.publicKey;
456
- ctx.body.keyId = newKeyPair.keyId;
457
- ctx.body.fingerprint = newKeyPair.fingerprint;
458
- ctx.body.algorithm = newKeyPair.algorithm;
459
- ctx.body.keySize = Buffer.from(newKeyPair.publicKey, "base64").length;
460
- const token = await generateClientToken(
461
- {
462
- userId: currentSession.userId,
463
- keyId: currentSession.keyId,
464
- action: "rotate_key",
465
- timestamp: Date.now()
466
- },
467
- currentSession.privateKey,
468
- currentSession.algorithm,
469
- { expiresIn: "15m" }
470
- );
471
- ctx.headers["Authorization"] = `Bearer ${token}`;
472
- ctx.headers["X-Key-Id"] = currentSession.keyId;
473
- ctx.metadata.newPrivateKey = newKeyPair.privateKey;
474
- ctx.metadata.newKeyId = newKeyPair.keyId;
475
- ctx.metadata.newAlgorithm = newKeyPair.algorithm;
476
- ctx.metadata.userId = currentSession.userId;
477
- } catch (error) {
478
- const err = error;
479
- authLogger3.error("Failed to prepare key rotation", err);
480
- }
481
- await next();
482
- },
483
- response: async (ctx, next) => {
484
- if (ctx.response.status !== 200) {
485
- await next();
486
- return;
487
- }
488
- if (!ctx.metadata.newPrivateKey || !ctx.metadata.userId) {
489
- authLogger3.error("Missing key rotation metadata");
490
- await next();
491
- return;
492
- }
493
- try {
494
- const ttl = getSessionTtl();
495
- const newSessionData = {
496
- userId: ctx.metadata.userId,
497
- privateKey: ctx.metadata.newPrivateKey,
498
- keyId: ctx.metadata.newKeyId,
499
- algorithm: ctx.metadata.newAlgorithm
500
- };
501
- const sealed = await sealSession(newSessionData, ttl);
502
- ctx.setCookies.push({
503
- name: COOKIE_NAMES.SESSION,
504
- value: sealed,
505
- options: {
506
- httpOnly: true,
507
- secure: process.env.NODE_ENV === "production",
508
- sameSite: "strict",
509
- maxAge: ttl,
510
- path: "/"
511
- }
512
- });
513
- ctx.setCookies.push({
514
- name: COOKIE_NAMES.SESSION_KEY_ID,
515
- value: ctx.metadata.newKeyId,
516
- options: {
517
- httpOnly: true,
518
- secure: process.env.NODE_ENV === "production",
519
- sameSite: "strict",
520
- maxAge: ttl,
521
- path: "/"
522
- }
523
- });
524
- } catch (error) {
525
- const err = error;
526
- authLogger3.error("Failed to update session after rotation", err);
527
- }
528
- await next();
529
- }
530
- };
531
-
532
- // src/adapters/nextjs/interceptors/index.ts
533
- var authInterceptors = [
534
- loginRegisterInterceptor,
535
- keyRotationInterceptor,
536
- generalAuthInterceptor
537
- ];
538
- registerInterceptors("auth", authInterceptors);
539
-
540
- // src/adapters/nextjs/guards/require-auth.tsx
541
- import { redirect } from "next/navigation";
542
- import { Fragment, jsx } from "react/jsx-runtime";
543
- async function RequireAuth({
544
- children,
545
- redirectTo = "/login",
546
- fallback
547
- }) {
548
- const session = await getSession();
549
- if (!session) {
550
- if (fallback) {
551
- return /* @__PURE__ */ jsx(Fragment, { children: fallback });
552
- }
553
- redirect(redirectTo);
554
- }
555
- return /* @__PURE__ */ jsx(Fragment, { children });
556
- }
557
-
558
- // src/adapters/nextjs/guards/require-role.tsx
559
- import { redirect as redirect2 } from "next/navigation";
560
-
561
- // src/lib/api/auth-me.ts
562
- import { client } from "@spfn/core/client";
563
-
564
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/guard/value.mjs
565
- var value_exports = {};
566
- __export(value_exports, {
567
- HasPropertyKey: () => HasPropertyKey,
568
- IsArray: () => IsArray,
569
- IsAsyncIterator: () => IsAsyncIterator,
570
- IsBigInt: () => IsBigInt,
571
- IsBoolean: () => IsBoolean,
572
- IsDate: () => IsDate,
573
- IsFunction: () => IsFunction,
574
- IsIterator: () => IsIterator,
575
- IsNull: () => IsNull,
576
- IsNumber: () => IsNumber,
577
- IsObject: () => IsObject,
578
- IsRegExp: () => IsRegExp,
579
- IsString: () => IsString,
580
- IsSymbol: () => IsSymbol,
581
- IsUint8Array: () => IsUint8Array,
582
- IsUndefined: () => IsUndefined
583
- });
584
- function HasPropertyKey(value, key) {
585
- return key in value;
586
- }
587
- function IsAsyncIterator(value) {
588
- return IsObject(value) && !IsArray(value) && !IsUint8Array(value) && Symbol.asyncIterator in value;
589
- }
590
- function IsArray(value) {
591
- return Array.isArray(value);
592
- }
593
- function IsBigInt(value) {
594
- return typeof value === "bigint";
595
- }
596
- function IsBoolean(value) {
597
- return typeof value === "boolean";
598
- }
599
- function IsDate(value) {
600
- return value instanceof globalThis.Date;
601
- }
602
- function IsFunction(value) {
603
- return typeof value === "function";
604
- }
605
- function IsIterator(value) {
606
- return IsObject(value) && !IsArray(value) && !IsUint8Array(value) && Symbol.iterator in value;
607
- }
608
- function IsNull(value) {
609
- return value === null;
610
- }
611
- function IsNumber(value) {
612
- return typeof value === "number";
613
- }
614
- function IsObject(value) {
615
- return typeof value === "object" && value !== null;
616
- }
617
- function IsRegExp(value) {
618
- return value instanceof globalThis.RegExp;
619
- }
620
- function IsString(value) {
621
- return typeof value === "string";
622
- }
623
- function IsSymbol(value) {
624
- return typeof value === "symbol";
625
- }
626
- function IsUint8Array(value) {
627
- return value instanceof globalThis.Uint8Array;
628
- }
629
- function IsUndefined(value) {
630
- return value === void 0;
631
- }
632
-
633
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/clone/value.mjs
634
- function ArrayType(value) {
635
- return value.map((value2) => Visit(value2));
636
- }
637
- function DateType(value) {
638
- return new Date(value.getTime());
639
- }
640
- function Uint8ArrayType(value) {
641
- return new Uint8Array(value);
642
- }
643
- function RegExpType(value) {
644
- return new RegExp(value.source, value.flags);
645
- }
646
- function ObjectType(value) {
647
- const result = {};
648
- for (const key of Object.getOwnPropertyNames(value)) {
649
- result[key] = Visit(value[key]);
650
- }
651
- for (const key of Object.getOwnPropertySymbols(value)) {
652
- result[key] = Visit(value[key]);
653
- }
654
- return result;
655
- }
656
- function Visit(value) {
657
- return IsArray(value) ? ArrayType(value) : IsDate(value) ? DateType(value) : IsUint8Array(value) ? Uint8ArrayType(value) : IsRegExp(value) ? RegExpType(value) : IsObject(value) ? ObjectType(value) : value;
658
- }
659
- function Clone(value) {
660
- return Visit(value);
661
- }
662
-
663
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/clone/type.mjs
664
- function CloneType(schema, options) {
665
- return options === void 0 ? Clone(schema) : Clone({ ...options, ...schema });
666
- }
667
-
668
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/value/guard/guard.mjs
669
- function IsObject2(value) {
670
- return value !== null && typeof value === "object";
671
- }
672
- function IsArray2(value) {
673
- return globalThis.Array.isArray(value) && !globalThis.ArrayBuffer.isView(value);
674
- }
675
- function IsUndefined2(value) {
676
- return value === void 0;
677
- }
678
- function IsNumber2(value) {
679
- return typeof value === "number";
680
- }
681
-
682
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/system/policy.mjs
683
- var TypeSystemPolicy;
684
- (function(TypeSystemPolicy2) {
685
- TypeSystemPolicy2.InstanceMode = "default";
686
- TypeSystemPolicy2.ExactOptionalPropertyTypes = false;
687
- TypeSystemPolicy2.AllowArrayObject = false;
688
- TypeSystemPolicy2.AllowNaN = false;
689
- TypeSystemPolicy2.AllowNullVoid = false;
690
- function IsExactOptionalProperty(value, key) {
691
- return TypeSystemPolicy2.ExactOptionalPropertyTypes ? key in value : value[key] !== void 0;
692
- }
693
- TypeSystemPolicy2.IsExactOptionalProperty = IsExactOptionalProperty;
694
- function IsObjectLike(value) {
695
- const isObject = IsObject2(value);
696
- return TypeSystemPolicy2.AllowArrayObject ? isObject : isObject && !IsArray2(value);
697
- }
698
- TypeSystemPolicy2.IsObjectLike = IsObjectLike;
699
- function IsRecordLike(value) {
700
- return IsObjectLike(value) && !(value instanceof Date) && !(value instanceof Uint8Array);
701
- }
702
- TypeSystemPolicy2.IsRecordLike = IsRecordLike;
703
- function IsNumberLike(value) {
704
- return TypeSystemPolicy2.AllowNaN ? IsNumber2(value) : Number.isFinite(value);
705
- }
706
- TypeSystemPolicy2.IsNumberLike = IsNumberLike;
707
- function IsVoidLike(value) {
708
- const isUndefined = IsUndefined2(value);
709
- return TypeSystemPolicy2.AllowNullVoid ? isUndefined || value === null : isUndefined;
710
- }
711
- TypeSystemPolicy2.IsVoidLike = IsVoidLike;
712
- })(TypeSystemPolicy || (TypeSystemPolicy = {}));
713
-
714
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/create/immutable.mjs
715
- function ImmutableArray(value) {
716
- return globalThis.Object.freeze(value).map((value2) => Immutable(value2));
717
- }
718
- function ImmutableDate(value) {
719
- return value;
720
- }
721
- function ImmutableUint8Array(value) {
722
- return value;
723
- }
724
- function ImmutableRegExp(value) {
725
- return value;
726
- }
727
- function ImmutableObject(value) {
728
- const result = {};
729
- for (const key of Object.getOwnPropertyNames(value)) {
730
- result[key] = Immutable(value[key]);
731
- }
732
- for (const key of Object.getOwnPropertySymbols(value)) {
733
- result[key] = Immutable(value[key]);
734
- }
735
- return globalThis.Object.freeze(result);
736
- }
737
- function Immutable(value) {
738
- return IsArray(value) ? ImmutableArray(value) : IsDate(value) ? ImmutableDate(value) : IsUint8Array(value) ? ImmutableUint8Array(value) : IsRegExp(value) ? ImmutableRegExp(value) : IsObject(value) ? ImmutableObject(value) : value;
739
- }
740
-
741
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/create/type.mjs
742
- function CreateType(schema, options) {
743
- const result = options !== void 0 ? { ...options, ...schema } : schema;
744
- switch (TypeSystemPolicy.InstanceMode) {
745
- case "freeze":
746
- return Immutable(result);
747
- case "clone":
748
- return Clone(result);
749
- default:
750
- return result;
751
- }
752
- }
753
-
754
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/error/error.mjs
755
- var TypeBoxError = class extends Error {
756
- constructor(message) {
757
- super(message);
758
- }
759
- };
760
-
761
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/symbols/symbols.mjs
762
- var TransformKind = Symbol.for("TypeBox.Transform");
763
- var ReadonlyKind = Symbol.for("TypeBox.Readonly");
764
- var OptionalKind = Symbol.for("TypeBox.Optional");
765
- var Hint = Symbol.for("TypeBox.Hint");
766
- var Kind = Symbol.for("TypeBox.Kind");
767
-
768
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/guard/kind.mjs
769
- function IsReadonly(value) {
770
- return IsObject(value) && value[ReadonlyKind] === "Readonly";
771
- }
772
- function IsOptional(value) {
773
- return IsObject(value) && value[OptionalKind] === "Optional";
774
- }
775
- function IsAny(value) {
776
- return IsKindOf(value, "Any");
777
- }
778
- function IsArgument(value) {
779
- return IsKindOf(value, "Argument");
780
- }
781
- function IsArray3(value) {
782
- return IsKindOf(value, "Array");
783
- }
784
- function IsAsyncIterator2(value) {
785
- return IsKindOf(value, "AsyncIterator");
786
- }
787
- function IsBigInt2(value) {
788
- return IsKindOf(value, "BigInt");
789
- }
790
- function IsBoolean2(value) {
791
- return IsKindOf(value, "Boolean");
792
- }
793
- function IsComputed(value) {
794
- return IsKindOf(value, "Computed");
795
- }
796
- function IsConstructor(value) {
797
- return IsKindOf(value, "Constructor");
798
- }
799
- function IsDate2(value) {
800
- return IsKindOf(value, "Date");
801
- }
802
- function IsFunction2(value) {
803
- return IsKindOf(value, "Function");
804
- }
805
- function IsInteger(value) {
806
- return IsKindOf(value, "Integer");
807
- }
808
- function IsIntersect(value) {
809
- return IsKindOf(value, "Intersect");
810
- }
811
- function IsIterator2(value) {
812
- return IsKindOf(value, "Iterator");
813
- }
814
- function IsKindOf(value, kind) {
815
- return IsObject(value) && Kind in value && value[Kind] === kind;
816
- }
817
- function IsLiteralValue(value) {
818
- return IsBoolean(value) || IsNumber(value) || IsString(value);
819
- }
820
- function IsLiteral(value) {
821
- return IsKindOf(value, "Literal");
822
- }
823
- function IsMappedKey(value) {
824
- return IsKindOf(value, "MappedKey");
825
- }
826
- function IsMappedResult(value) {
827
- return IsKindOf(value, "MappedResult");
828
- }
829
- function IsNever(value) {
830
- return IsKindOf(value, "Never");
831
- }
832
- function IsNot(value) {
833
- return IsKindOf(value, "Not");
834
- }
835
- function IsNull2(value) {
836
- return IsKindOf(value, "Null");
837
- }
838
- function IsNumber3(value) {
839
- return IsKindOf(value, "Number");
840
- }
841
- function IsObject3(value) {
842
- return IsKindOf(value, "Object");
843
- }
844
- function IsPromise(value) {
845
- return IsKindOf(value, "Promise");
846
- }
847
- function IsRecord(value) {
848
- return IsKindOf(value, "Record");
849
- }
850
- function IsRef(value) {
851
- return IsKindOf(value, "Ref");
852
- }
853
- function IsRegExp2(value) {
854
- return IsKindOf(value, "RegExp");
855
- }
856
- function IsString2(value) {
857
- return IsKindOf(value, "String");
858
- }
859
- function IsSymbol2(value) {
860
- return IsKindOf(value, "Symbol");
861
- }
862
- function IsTemplateLiteral(value) {
863
- return IsKindOf(value, "TemplateLiteral");
864
- }
865
- function IsThis(value) {
866
- return IsKindOf(value, "This");
867
- }
868
- function IsTransform(value) {
869
- return IsObject(value) && TransformKind in value;
870
- }
871
- function IsTuple(value) {
872
- return IsKindOf(value, "Tuple");
873
- }
874
- function IsUndefined3(value) {
875
- return IsKindOf(value, "Undefined");
876
- }
877
- function IsUnion(value) {
878
- return IsKindOf(value, "Union");
879
- }
880
- function IsUint8Array2(value) {
881
- return IsKindOf(value, "Uint8Array");
882
- }
883
- function IsUnknown(value) {
884
- return IsKindOf(value, "Unknown");
885
- }
886
- function IsUnsafe(value) {
887
- return IsKindOf(value, "Unsafe");
888
- }
889
- function IsVoid(value) {
890
- return IsKindOf(value, "Void");
891
- }
892
- function IsKind(value) {
893
- return IsObject(value) && Kind in value && IsString(value[Kind]);
894
- }
895
- function IsSchema(value) {
896
- 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);
897
- }
898
-
899
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/guard/type.mjs
900
- var type_exports = {};
901
- __export(type_exports, {
902
- IsAny: () => IsAny2,
903
- IsArgument: () => IsArgument2,
904
- IsArray: () => IsArray4,
905
- IsAsyncIterator: () => IsAsyncIterator3,
906
- IsBigInt: () => IsBigInt3,
907
- IsBoolean: () => IsBoolean3,
908
- IsComputed: () => IsComputed2,
909
- IsConstructor: () => IsConstructor2,
910
- IsDate: () => IsDate3,
911
- IsFunction: () => IsFunction3,
912
- IsImport: () => IsImport,
913
- IsInteger: () => IsInteger2,
914
- IsIntersect: () => IsIntersect2,
915
- IsIterator: () => IsIterator3,
916
- IsKind: () => IsKind2,
917
- IsKindOf: () => IsKindOf2,
918
- IsLiteral: () => IsLiteral2,
919
- IsLiteralBoolean: () => IsLiteralBoolean,
920
- IsLiteralNumber: () => IsLiteralNumber,
921
- IsLiteralString: () => IsLiteralString,
922
- IsLiteralValue: () => IsLiteralValue2,
923
- IsMappedKey: () => IsMappedKey2,
924
- IsMappedResult: () => IsMappedResult2,
925
- IsNever: () => IsNever2,
926
- IsNot: () => IsNot2,
927
- IsNull: () => IsNull3,
928
- IsNumber: () => IsNumber4,
929
- IsObject: () => IsObject4,
930
- IsOptional: () => IsOptional2,
931
- IsPromise: () => IsPromise2,
932
- IsProperties: () => IsProperties,
933
- IsReadonly: () => IsReadonly2,
934
- IsRecord: () => IsRecord2,
935
- IsRecursive: () => IsRecursive,
936
- IsRef: () => IsRef2,
937
- IsRegExp: () => IsRegExp3,
938
- IsSchema: () => IsSchema2,
939
- IsString: () => IsString3,
940
- IsSymbol: () => IsSymbol3,
941
- IsTemplateLiteral: () => IsTemplateLiteral2,
942
- IsThis: () => IsThis2,
943
- IsTransform: () => IsTransform2,
944
- IsTuple: () => IsTuple2,
945
- IsUint8Array: () => IsUint8Array3,
946
- IsUndefined: () => IsUndefined4,
947
- IsUnion: () => IsUnion2,
948
- IsUnionLiteral: () => IsUnionLiteral,
949
- IsUnknown: () => IsUnknown2,
950
- IsUnsafe: () => IsUnsafe2,
951
- IsVoid: () => IsVoid2,
952
- TypeGuardUnknownTypeError: () => TypeGuardUnknownTypeError
953
- });
954
- var TypeGuardUnknownTypeError = class extends TypeBoxError {
955
- };
956
- var KnownTypes = [
957
- "Argument",
958
- "Any",
959
- "Array",
960
- "AsyncIterator",
961
- "BigInt",
962
- "Boolean",
963
- "Computed",
964
- "Constructor",
965
- "Date",
966
- "Enum",
967
- "Function",
968
- "Integer",
969
- "Intersect",
970
- "Iterator",
971
- "Literal",
972
- "MappedKey",
973
- "MappedResult",
974
- "Not",
975
- "Null",
976
- "Number",
977
- "Object",
978
- "Promise",
979
- "Record",
980
- "Ref",
981
- "RegExp",
982
- "String",
983
- "Symbol",
984
- "TemplateLiteral",
985
- "This",
986
- "Tuple",
987
- "Undefined",
988
- "Union",
989
- "Uint8Array",
990
- "Unknown",
991
- "Void"
992
- ];
993
- function IsPattern(value) {
994
- try {
995
- new RegExp(value);
996
- return true;
997
- } catch {
998
- return false;
999
- }
1000
- }
1001
- function IsControlCharacterFree(value) {
1002
- if (!IsString(value))
1003
- return false;
1004
- for (let i = 0; i < value.length; i++) {
1005
- const code = value.charCodeAt(i);
1006
- if (code >= 7 && code <= 13 || code === 27 || code === 127) {
1007
- return false;
1008
- }
1009
- }
1010
- return true;
1011
- }
1012
- function IsAdditionalProperties(value) {
1013
- return IsOptionalBoolean(value) || IsSchema2(value);
1014
- }
1015
- function IsOptionalBigInt(value) {
1016
- return IsUndefined(value) || IsBigInt(value);
1017
- }
1018
- function IsOptionalNumber(value) {
1019
- return IsUndefined(value) || IsNumber(value);
1020
- }
1021
- function IsOptionalBoolean(value) {
1022
- return IsUndefined(value) || IsBoolean(value);
1023
- }
1024
- function IsOptionalString(value) {
1025
- return IsUndefined(value) || IsString(value);
1026
- }
1027
- function IsOptionalPattern(value) {
1028
- return IsUndefined(value) || IsString(value) && IsControlCharacterFree(value) && IsPattern(value);
1029
- }
1030
- function IsOptionalFormat(value) {
1031
- return IsUndefined(value) || IsString(value) && IsControlCharacterFree(value);
1032
- }
1033
- function IsOptionalSchema(value) {
1034
- return IsUndefined(value) || IsSchema2(value);
1035
- }
1036
- function IsReadonly2(value) {
1037
- return IsObject(value) && value[ReadonlyKind] === "Readonly";
1038
- }
1039
- function IsOptional2(value) {
1040
- return IsObject(value) && value[OptionalKind] === "Optional";
1041
- }
1042
- function IsAny2(value) {
1043
- return IsKindOf2(value, "Any") && IsOptionalString(value.$id);
1044
- }
1045
- function IsArgument2(value) {
1046
- return IsKindOf2(value, "Argument") && IsNumber(value.index);
1047
- }
1048
- function IsArray4(value) {
1049
- 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);
1050
- }
1051
- function IsAsyncIterator3(value) {
1052
- return IsKindOf2(value, "AsyncIterator") && value.type === "AsyncIterator" && IsOptionalString(value.$id) && IsSchema2(value.items);
1053
- }
1054
- function IsBigInt3(value) {
1055
- 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);
1056
- }
1057
- function IsBoolean3(value) {
1058
- return IsKindOf2(value, "Boolean") && value.type === "boolean" && IsOptionalString(value.$id);
1059
- }
1060
- function IsComputed2(value) {
1061
- return IsKindOf2(value, "Computed") && IsString(value.target) && IsArray(value.parameters) && value.parameters.every((schema) => IsSchema2(schema));
1062
- }
1063
- function IsConstructor2(value) {
1064
- return IsKindOf2(value, "Constructor") && value.type === "Constructor" && IsOptionalString(value.$id) && IsArray(value.parameters) && value.parameters.every((schema) => IsSchema2(schema)) && IsSchema2(value.returns);
1065
- }
1066
- function IsDate3(value) {
1067
- 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);
1068
- }
1069
- function IsFunction3(value) {
1070
- return IsKindOf2(value, "Function") && value.type === "Function" && IsOptionalString(value.$id) && IsArray(value.parameters) && value.parameters.every((schema) => IsSchema2(schema)) && IsSchema2(value.returns);
1071
- }
1072
- function IsImport(value) {
1073
- return IsKindOf2(value, "Import") && HasPropertyKey(value, "$defs") && IsObject(value.$defs) && IsProperties(value.$defs) && HasPropertyKey(value, "$ref") && IsString(value.$ref) && value.$ref in value.$defs;
1074
- }
1075
- function IsInteger2(value) {
1076
- 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);
1077
- }
1078
- function IsProperties(value) {
1079
- return IsObject(value) && Object.entries(value).every(([key, schema]) => IsControlCharacterFree(key) && IsSchema2(schema));
1080
- }
1081
- function IsIntersect2(value) {
1082
- 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);
1083
- }
1084
- function IsIterator3(value) {
1085
- return IsKindOf2(value, "Iterator") && value.type === "Iterator" && IsOptionalString(value.$id) && IsSchema2(value.items);
1086
- }
1087
- function IsKindOf2(value, kind) {
1088
- return IsObject(value) && Kind in value && value[Kind] === kind;
1089
- }
1090
- function IsLiteralString(value) {
1091
- return IsLiteral2(value) && IsString(value.const);
1092
- }
1093
- function IsLiteralNumber(value) {
1094
- return IsLiteral2(value) && IsNumber(value.const);
1095
- }
1096
- function IsLiteralBoolean(value) {
1097
- return IsLiteral2(value) && IsBoolean(value.const);
1098
- }
1099
- function IsLiteral2(value) {
1100
- return IsKindOf2(value, "Literal") && IsOptionalString(value.$id) && IsLiteralValue2(value.const);
1101
- }
1102
- function IsLiteralValue2(value) {
1103
- return IsBoolean(value) || IsNumber(value) || IsString(value);
1104
- }
1105
- function IsMappedKey2(value) {
1106
- return IsKindOf2(value, "MappedKey") && IsArray(value.keys) && value.keys.every((key) => IsNumber(key) || IsString(key));
1107
- }
1108
- function IsMappedResult2(value) {
1109
- return IsKindOf2(value, "MappedResult") && IsProperties(value.properties);
1110
- }
1111
- function IsNever2(value) {
1112
- return IsKindOf2(value, "Never") && IsObject(value.not) && Object.getOwnPropertyNames(value.not).length === 0;
1113
- }
1114
- function IsNot2(value) {
1115
- return IsKindOf2(value, "Not") && IsSchema2(value.not);
1116
- }
1117
- function IsNull3(value) {
1118
- return IsKindOf2(value, "Null") && value.type === "null" && IsOptionalString(value.$id);
1119
- }
1120
- function IsNumber4(value) {
1121
- 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);
1122
- }
1123
- function IsObject4(value) {
1124
- return IsKindOf2(value, "Object") && value.type === "object" && IsOptionalString(value.$id) && IsProperties(value.properties) && IsAdditionalProperties(value.additionalProperties) && IsOptionalNumber(value.minProperties) && IsOptionalNumber(value.maxProperties);
1125
- }
1126
- function IsPromise2(value) {
1127
- return IsKindOf2(value, "Promise") && value.type === "Promise" && IsOptionalString(value.$id) && IsSchema2(value.item);
1128
- }
1129
- function IsRecord2(value) {
1130
- return IsKindOf2(value, "Record") && value.type === "object" && IsOptionalString(value.$id) && IsAdditionalProperties(value.additionalProperties) && IsObject(value.patternProperties) && ((schema) => {
1131
- const keys = Object.getOwnPropertyNames(schema.patternProperties);
1132
- return keys.length === 1 && IsPattern(keys[0]) && IsObject(schema.patternProperties) && IsSchema2(schema.patternProperties[keys[0]]);
1133
- })(value);
1134
- }
1135
- function IsRecursive(value) {
1136
- return IsObject(value) && Hint in value && value[Hint] === "Recursive";
1137
- }
1138
- function IsRef2(value) {
1139
- return IsKindOf2(value, "Ref") && IsOptionalString(value.$id) && IsString(value.$ref);
1140
- }
1141
- function IsRegExp3(value) {
1142
- return IsKindOf2(value, "RegExp") && IsOptionalString(value.$id) && IsString(value.source) && IsString(value.flags) && IsOptionalNumber(value.maxLength) && IsOptionalNumber(value.minLength);
1143
- }
1144
- function IsString3(value) {
1145
- return IsKindOf2(value, "String") && value.type === "string" && IsOptionalString(value.$id) && IsOptionalNumber(value.minLength) && IsOptionalNumber(value.maxLength) && IsOptionalPattern(value.pattern) && IsOptionalFormat(value.format);
1146
- }
1147
- function IsSymbol3(value) {
1148
- return IsKindOf2(value, "Symbol") && value.type === "symbol" && IsOptionalString(value.$id);
1149
- }
1150
- function IsTemplateLiteral2(value) {
1151
- return IsKindOf2(value, "TemplateLiteral") && value.type === "string" && IsString(value.pattern) && value.pattern[0] === "^" && value.pattern[value.pattern.length - 1] === "$";
1152
- }
1153
- function IsThis2(value) {
1154
- return IsKindOf2(value, "This") && IsOptionalString(value.$id) && IsString(value.$ref);
1155
- }
1156
- function IsTransform2(value) {
1157
- return IsObject(value) && TransformKind in value;
1158
- }
1159
- function IsTuple2(value) {
1160
- return IsKindOf2(value, "Tuple") && value.type === "array" && IsOptionalString(value.$id) && IsNumber(value.minItems) && IsNumber(value.maxItems) && value.minItems === value.maxItems && // empty
1161
- (IsUndefined(value.items) && IsUndefined(value.additionalItems) && value.minItems === 0 || IsArray(value.items) && value.items.every((schema) => IsSchema2(schema)));
1162
- }
1163
- function IsUndefined4(value) {
1164
- return IsKindOf2(value, "Undefined") && value.type === "undefined" && IsOptionalString(value.$id);
1165
- }
1166
- function IsUnionLiteral(value) {
1167
- return IsUnion2(value) && value.anyOf.every((schema) => IsLiteralString(schema) || IsLiteralNumber(schema));
1168
- }
1169
- function IsUnion2(value) {
1170
- return IsKindOf2(value, "Union") && IsOptionalString(value.$id) && IsObject(value) && IsArray(value.anyOf) && value.anyOf.every((schema) => IsSchema2(schema));
1171
- }
1172
- function IsUint8Array3(value) {
1173
- return IsKindOf2(value, "Uint8Array") && value.type === "Uint8Array" && IsOptionalString(value.$id) && IsOptionalNumber(value.minByteLength) && IsOptionalNumber(value.maxByteLength);
1174
- }
1175
- function IsUnknown2(value) {
1176
- return IsKindOf2(value, "Unknown") && IsOptionalString(value.$id);
1177
- }
1178
- function IsUnsafe2(value) {
1179
- return IsKindOf2(value, "Unsafe");
1180
- }
1181
- function IsVoid2(value) {
1182
- return IsKindOf2(value, "Void") && value.type === "void" && IsOptionalString(value.$id);
1183
- }
1184
- function IsKind2(value) {
1185
- return IsObject(value) && Kind in value && IsString(value[Kind]) && !KnownTypes.includes(value[Kind]);
1186
- }
1187
- function IsSchema2(value) {
1188
- 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));
1189
- }
1190
-
1191
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/patterns/patterns.mjs
1192
- var PatternBoolean = "(true|false)";
1193
- var PatternNumber = "(0|[1-9][0-9]*)";
1194
- var PatternString = "(.*)";
1195
- var PatternNever = "(?!.*)";
1196
- var PatternBooleanExact = `^${PatternBoolean}$`;
1197
- var PatternNumberExact = `^${PatternNumber}$`;
1198
- var PatternStringExact = `^${PatternString}$`;
1199
- var PatternNeverExact = `^${PatternNever}$`;
1200
-
1201
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/sets/set.mjs
1202
- function SetIncludes(T, S) {
1203
- return T.includes(S);
1204
- }
1205
- function SetDistinct(T) {
1206
- return [...new Set(T)];
1207
- }
1208
- function SetIntersect(T, S) {
1209
- return T.filter((L) => S.includes(L));
1210
- }
1211
- function SetIntersectManyResolve(T, Init) {
1212
- return T.reduce((Acc, L) => {
1213
- return SetIntersect(Acc, L);
1214
- }, Init);
1215
- }
1216
- function SetIntersectMany(T) {
1217
- return T.length === 1 ? T[0] : T.length > 1 ? SetIntersectManyResolve(T.slice(1), T[0]) : [];
1218
- }
1219
- function SetUnionMany(T) {
1220
- const Acc = [];
1221
- for (const L of T)
1222
- Acc.push(...L);
1223
- return Acc;
1224
- }
1225
-
1226
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/any/any.mjs
1227
- function Any(options) {
1228
- return CreateType({ [Kind]: "Any" }, options);
1229
- }
1230
-
1231
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/array/array.mjs
1232
- function Array2(items, options) {
1233
- return CreateType({ [Kind]: "Array", type: "array", items }, options);
1234
- }
1235
-
1236
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/argument/argument.mjs
1237
- function Argument(index) {
1238
- return CreateType({ [Kind]: "Argument", index });
1239
- }
1240
-
1241
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/async-iterator/async-iterator.mjs
1242
- function AsyncIterator(items, options) {
1243
- return CreateType({ [Kind]: "AsyncIterator", type: "AsyncIterator", items }, options);
1244
- }
1245
-
1246
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/computed/computed.mjs
1247
- function Computed(target, parameters, options) {
1248
- return CreateType({ [Kind]: "Computed", target, parameters }, options);
1249
- }
1250
-
1251
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/discard/discard.mjs
1252
- function DiscardKey(value, key) {
1253
- const { [key]: _, ...rest } = value;
1254
- return rest;
1255
- }
1256
- function Discard(value, keys) {
1257
- return keys.reduce((acc, key) => DiscardKey(acc, key), value);
1258
- }
1259
-
1260
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/never/never.mjs
1261
- function Never(options) {
1262
- return CreateType({ [Kind]: "Never", not: {} }, options);
1263
- }
1264
-
1265
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/mapped/mapped-result.mjs
1266
- function MappedResult(properties) {
1267
- return CreateType({
1268
- [Kind]: "MappedResult",
1269
- properties
1270
- });
1271
- }
1272
-
1273
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/constructor/constructor.mjs
1274
- function Constructor(parameters, returns, options) {
1275
- return CreateType({ [Kind]: "Constructor", type: "Constructor", parameters, returns }, options);
1276
- }
1277
-
1278
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/function/function.mjs
1279
- function Function(parameters, returns, options) {
1280
- return CreateType({ [Kind]: "Function", type: "Function", parameters, returns }, options);
1281
- }
1282
-
1283
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/union/union-create.mjs
1284
- function UnionCreate(T, options) {
1285
- return CreateType({ [Kind]: "Union", anyOf: T }, options);
1286
- }
1287
-
1288
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/union/union-evaluated.mjs
1289
- function IsUnionOptional(types) {
1290
- return types.some((type) => IsOptional(type));
1291
- }
1292
- function RemoveOptionalFromRest(types) {
1293
- return types.map((left) => IsOptional(left) ? RemoveOptionalFromType(left) : left);
1294
- }
1295
- function RemoveOptionalFromType(T) {
1296
- return Discard(T, [OptionalKind]);
1297
- }
1298
- function ResolveUnion(types, options) {
1299
- const isOptional = IsUnionOptional(types);
1300
- return isOptional ? Optional(UnionCreate(RemoveOptionalFromRest(types), options)) : UnionCreate(RemoveOptionalFromRest(types), options);
1301
- }
1302
- function UnionEvaluated(T, options) {
1303
- return T.length === 1 ? CreateType(T[0], options) : T.length === 0 ? Never(options) : ResolveUnion(T, options);
1304
- }
1305
-
1306
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/union/union.mjs
1307
- function Union(types, options) {
1308
- return types.length === 0 ? Never(options) : types.length === 1 ? CreateType(types[0], options) : UnionCreate(types, options);
1309
- }
1310
-
1311
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/template-literal/parse.mjs
1312
- var TemplateLiteralParserError = class extends TypeBoxError {
1313
- };
1314
- function Unescape(pattern) {
1315
- return pattern.replace(/\\\$/g, "$").replace(/\\\*/g, "*").replace(/\\\^/g, "^").replace(/\\\|/g, "|").replace(/\\\(/g, "(").replace(/\\\)/g, ")");
1316
- }
1317
- function IsNonEscaped(pattern, index, char) {
1318
- return pattern[index] === char && pattern.charCodeAt(index - 1) !== 92;
1319
- }
1320
- function IsOpenParen(pattern, index) {
1321
- return IsNonEscaped(pattern, index, "(");
1322
- }
1323
- function IsCloseParen(pattern, index) {
1324
- return IsNonEscaped(pattern, index, ")");
1325
- }
1326
- function IsSeparator(pattern, index) {
1327
- return IsNonEscaped(pattern, index, "|");
1328
- }
1329
- function IsGroup(pattern) {
1330
- if (!(IsOpenParen(pattern, 0) && IsCloseParen(pattern, pattern.length - 1)))
1331
- return false;
1332
- let count = 0;
1333
- for (let index = 0; index < pattern.length; index++) {
1334
- if (IsOpenParen(pattern, index))
1335
- count += 1;
1336
- if (IsCloseParen(pattern, index))
1337
- count -= 1;
1338
- if (count === 0 && index !== pattern.length - 1)
1339
- return false;
1340
- }
1341
- return true;
1342
- }
1343
- function InGroup(pattern) {
1344
- return pattern.slice(1, pattern.length - 1);
1345
- }
1346
- function IsPrecedenceOr(pattern) {
1347
- let count = 0;
1348
- for (let index = 0; index < pattern.length; index++) {
1349
- if (IsOpenParen(pattern, index))
1350
- count += 1;
1351
- if (IsCloseParen(pattern, index))
1352
- count -= 1;
1353
- if (IsSeparator(pattern, index) && count === 0)
1354
- return true;
1355
- }
1356
- return false;
1357
- }
1358
- function IsPrecedenceAnd(pattern) {
1359
- for (let index = 0; index < pattern.length; index++) {
1360
- if (IsOpenParen(pattern, index))
1361
- return true;
1362
- }
1363
- return false;
1364
- }
1365
- function Or(pattern) {
1366
- let [count, start] = [0, 0];
1367
- const expressions = [];
1368
- for (let index = 0; index < pattern.length; index++) {
1369
- if (IsOpenParen(pattern, index))
1370
- count += 1;
1371
- if (IsCloseParen(pattern, index))
1372
- count -= 1;
1373
- if (IsSeparator(pattern, index) && count === 0) {
1374
- const range2 = pattern.slice(start, index);
1375
- if (range2.length > 0)
1376
- expressions.push(TemplateLiteralParse(range2));
1377
- start = index + 1;
1378
- }
1379
- }
1380
- const range = pattern.slice(start);
1381
- if (range.length > 0)
1382
- expressions.push(TemplateLiteralParse(range));
1383
- if (expressions.length === 0)
1384
- return { type: "const", const: "" };
1385
- if (expressions.length === 1)
1386
- return expressions[0];
1387
- return { type: "or", expr: expressions };
1388
- }
1389
- function And(pattern) {
1390
- function Group(value, index) {
1391
- if (!IsOpenParen(value, index))
1392
- throw new TemplateLiteralParserError(`TemplateLiteralParser: Index must point to open parens`);
1393
- let count = 0;
1394
- for (let scan = index; scan < value.length; scan++) {
1395
- if (IsOpenParen(value, scan))
1396
- count += 1;
1397
- if (IsCloseParen(value, scan))
1398
- count -= 1;
1399
- if (count === 0)
1400
- return [index, scan];
1401
- }
1402
- throw new TemplateLiteralParserError(`TemplateLiteralParser: Unclosed group parens in expression`);
1403
- }
1404
- function Range(pattern2, index) {
1405
- for (let scan = index; scan < pattern2.length; scan++) {
1406
- if (IsOpenParen(pattern2, scan))
1407
- return [index, scan];
1408
- }
1409
- return [index, pattern2.length];
1410
- }
1411
- const expressions = [];
1412
- for (let index = 0; index < pattern.length; index++) {
1413
- if (IsOpenParen(pattern, index)) {
1414
- const [start, end] = Group(pattern, index);
1415
- const range = pattern.slice(start, end + 1);
1416
- expressions.push(TemplateLiteralParse(range));
1417
- index = end;
1418
- } else {
1419
- const [start, end] = Range(pattern, index);
1420
- const range = pattern.slice(start, end);
1421
- if (range.length > 0)
1422
- expressions.push(TemplateLiteralParse(range));
1423
- index = end - 1;
1424
- }
1425
- }
1426
- return expressions.length === 0 ? { type: "const", const: "" } : expressions.length === 1 ? expressions[0] : { type: "and", expr: expressions };
1427
- }
1428
- function TemplateLiteralParse(pattern) {
1429
- return IsGroup(pattern) ? TemplateLiteralParse(InGroup(pattern)) : IsPrecedenceOr(pattern) ? Or(pattern) : IsPrecedenceAnd(pattern) ? And(pattern) : { type: "const", const: Unescape(pattern) };
1430
- }
1431
- function TemplateLiteralParseExact(pattern) {
1432
- return TemplateLiteralParse(pattern.slice(1, pattern.length - 1));
1433
- }
1434
-
1435
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/template-literal/finite.mjs
1436
- var TemplateLiteralFiniteError = class extends TypeBoxError {
1437
- };
1438
- function IsNumberExpression(expression) {
1439
- 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]*";
1440
- }
1441
- function IsBooleanExpression(expression) {
1442
- 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";
1443
- }
1444
- function IsStringExpression(expression) {
1445
- return expression.type === "const" && expression.const === ".*";
1446
- }
1447
- function IsTemplateLiteralExpressionFinite(expression) {
1448
- 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 : (() => {
1449
- throw new TemplateLiteralFiniteError(`Unknown expression type`);
1450
- })();
1451
- }
1452
- function IsTemplateLiteralFinite(schema) {
1453
- const expression = TemplateLiteralParseExact(schema.pattern);
1454
- return IsTemplateLiteralExpressionFinite(expression);
1455
- }
1456
-
1457
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/template-literal/generate.mjs
1458
- var TemplateLiteralGenerateError = class extends TypeBoxError {
1459
- };
1460
- function* GenerateReduce(buffer) {
1461
- if (buffer.length === 1)
1462
- return yield* buffer[0];
1463
- for (const left of buffer[0]) {
1464
- for (const right of GenerateReduce(buffer.slice(1))) {
1465
- yield `${left}${right}`;
1466
- }
1467
- }
1468
- }
1469
- function* GenerateAnd(expression) {
1470
- return yield* GenerateReduce(expression.expr.map((expr) => [...TemplateLiteralExpressionGenerate(expr)]));
1471
- }
1472
- function* GenerateOr(expression) {
1473
- for (const expr of expression.expr)
1474
- yield* TemplateLiteralExpressionGenerate(expr);
1475
- }
1476
- function* GenerateConst(expression) {
1477
- return yield expression.const;
1478
- }
1479
- function* TemplateLiteralExpressionGenerate(expression) {
1480
- return expression.type === "and" ? yield* GenerateAnd(expression) : expression.type === "or" ? yield* GenerateOr(expression) : expression.type === "const" ? yield* GenerateConst(expression) : (() => {
1481
- throw new TemplateLiteralGenerateError("Unknown expression");
1482
- })();
1483
- }
1484
- function TemplateLiteralGenerate(schema) {
1485
- const expression = TemplateLiteralParseExact(schema.pattern);
1486
- return IsTemplateLiteralExpressionFinite(expression) ? [...TemplateLiteralExpressionGenerate(expression)] : [];
1487
- }
1488
-
1489
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/literal/literal.mjs
1490
- function Literal(value, options) {
1491
- return CreateType({
1492
- [Kind]: "Literal",
1493
- const: value,
1494
- type: typeof value
1495
- }, options);
1496
- }
1497
-
1498
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/boolean/boolean.mjs
1499
- function Boolean(options) {
1500
- return CreateType({ [Kind]: "Boolean", type: "boolean" }, options);
1501
- }
1502
-
1503
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/bigint/bigint.mjs
1504
- function BigInt(options) {
1505
- return CreateType({ [Kind]: "BigInt", type: "bigint" }, options);
1506
- }
1507
-
1508
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/number/number.mjs
1509
- function Number2(options) {
1510
- return CreateType({ [Kind]: "Number", type: "number" }, options);
1511
- }
1512
-
1513
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/string/string.mjs
1514
- function String(options) {
1515
- return CreateType({ [Kind]: "String", type: "string" }, options);
1516
- }
1517
-
1518
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/template-literal/syntax.mjs
1519
- function* FromUnion(syntax) {
1520
- const trim = syntax.trim().replace(/"|'/g, "");
1521
- return trim === "boolean" ? yield Boolean() : trim === "number" ? yield Number2() : trim === "bigint" ? yield BigInt() : trim === "string" ? yield String() : yield (() => {
1522
- const literals = trim.split("|").map((literal) => Literal(literal.trim()));
1523
- return literals.length === 0 ? Never() : literals.length === 1 ? literals[0] : UnionEvaluated(literals);
1524
- })();
1525
- }
1526
- function* FromTerminal(syntax) {
1527
- if (syntax[1] !== "{") {
1528
- const L = Literal("$");
1529
- const R = FromSyntax(syntax.slice(1));
1530
- return yield* [L, ...R];
1531
- }
1532
- for (let i = 2; i < syntax.length; i++) {
1533
- if (syntax[i] === "}") {
1534
- const L = FromUnion(syntax.slice(2, i));
1535
- const R = FromSyntax(syntax.slice(i + 1));
1536
- return yield* [...L, ...R];
1537
- }
1538
- }
1539
- yield Literal(syntax);
1540
- }
1541
- function* FromSyntax(syntax) {
1542
- for (let i = 0; i < syntax.length; i++) {
1543
- if (syntax[i] === "$") {
1544
- const L = Literal(syntax.slice(0, i));
1545
- const R = FromTerminal(syntax.slice(i));
1546
- return yield* [L, ...R];
1547
- }
1548
- }
1549
- yield Literal(syntax);
1550
- }
1551
- function TemplateLiteralSyntax(syntax) {
1552
- return [...FromSyntax(syntax)];
1553
- }
1554
-
1555
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/template-literal/pattern.mjs
1556
- var TemplateLiteralPatternError = class extends TypeBoxError {
1557
- };
1558
- function Escape(value) {
1559
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1560
- }
1561
- function Visit2(schema, acc) {
1562
- 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}` : (() => {
1563
- throw new TemplateLiteralPatternError(`Unexpected Kind '${schema[Kind]}'`);
1564
- })();
1565
- }
1566
- function TemplateLiteralPattern(kinds) {
1567
- return `^${kinds.map((schema) => Visit2(schema, "")).join("")}$`;
1568
- }
1569
-
1570
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/template-literal/union.mjs
1571
- function TemplateLiteralToUnion(schema) {
1572
- const R = TemplateLiteralGenerate(schema);
1573
- const L = R.map((S) => Literal(S));
1574
- return UnionEvaluated(L);
1575
- }
1576
-
1577
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/template-literal/template-literal.mjs
1578
- function TemplateLiteral(unresolved, options) {
1579
- const pattern = IsString(unresolved) ? TemplateLiteralPattern(TemplateLiteralSyntax(unresolved)) : TemplateLiteralPattern(unresolved);
1580
- return CreateType({ [Kind]: "TemplateLiteral", type: "string", pattern }, options);
1581
- }
1582
-
1583
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/indexed/indexed-property-keys.mjs
1584
- function FromTemplateLiteral(templateLiteral) {
1585
- const keys = TemplateLiteralGenerate(templateLiteral);
1586
- return keys.map((key) => key.toString());
1587
- }
1588
- function FromUnion2(types) {
1589
- const result = [];
1590
- for (const type of types)
1591
- result.push(...IndexPropertyKeys(type));
1592
- return result;
1593
- }
1594
- function FromLiteral(literalValue) {
1595
- return [literalValue.toString()];
1596
- }
1597
- function IndexPropertyKeys(type) {
1598
- return [...new Set(IsTemplateLiteral(type) ? FromTemplateLiteral(type) : IsUnion(type) ? FromUnion2(type.anyOf) : IsLiteral(type) ? FromLiteral(type.const) : IsNumber3(type) ? ["[number]"] : IsInteger(type) ? ["[number]"] : [])];
1599
- }
1600
-
1601
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/indexed/indexed-from-mapped-result.mjs
1602
- function FromProperties(type, properties, options) {
1603
- const result = {};
1604
- for (const K2 of Object.getOwnPropertyNames(properties)) {
1605
- result[K2] = Index(type, IndexPropertyKeys(properties[K2]), options);
1606
- }
1607
- return result;
1608
- }
1609
- function FromMappedResult(type, mappedResult, options) {
1610
- return FromProperties(type, mappedResult.properties, options);
1611
- }
1612
- function IndexFromMappedResult(type, mappedResult, options) {
1613
- const properties = FromMappedResult(type, mappedResult, options);
1614
- return MappedResult(properties);
1615
- }
1616
-
1617
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/indexed/indexed.mjs
1618
- function FromRest(types, key) {
1619
- return types.map((type) => IndexFromPropertyKey(type, key));
1620
- }
1621
- function FromIntersectRest(types) {
1622
- return types.filter((type) => !IsNever(type));
1623
- }
1624
- function FromIntersect(types, key) {
1625
- return IntersectEvaluated(FromIntersectRest(FromRest(types, key)));
1626
- }
1627
- function FromUnionRest(types) {
1628
- return types.some((L) => IsNever(L)) ? [] : types;
1629
- }
1630
- function FromUnion3(types, key) {
1631
- return UnionEvaluated(FromUnionRest(FromRest(types, key)));
1632
- }
1633
- function FromTuple(types, key) {
1634
- return key in types ? types[key] : key === "[number]" ? UnionEvaluated(types) : Never();
1635
- }
1636
- function FromArray(type, key) {
1637
- return key === "[number]" ? type : Never();
1638
- }
1639
- function FromProperty(properties, propertyKey) {
1640
- return propertyKey in properties ? properties[propertyKey] : Never();
1641
- }
1642
- function IndexFromPropertyKey(type, propertyKey) {
1643
- 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();
1644
- }
1645
- function IndexFromPropertyKeys(type, propertyKeys) {
1646
- return propertyKeys.map((propertyKey) => IndexFromPropertyKey(type, propertyKey));
1647
- }
1648
- function FromSchema(type, propertyKeys) {
1649
- return UnionEvaluated(IndexFromPropertyKeys(type, propertyKeys));
1650
- }
1651
- function Index(type, key, options) {
1652
- if (IsRef(type) || IsRef(key)) {
1653
- const error = `Index types using Ref parameters require both Type and Key to be of TSchema`;
1654
- if (!IsSchema(type) || !IsSchema(key))
1655
- throw new TypeBoxError(error);
1656
- return Computed("Index", [type, key]);
1657
- }
1658
- if (IsMappedResult(key))
1659
- return IndexFromMappedResult(type, key, options);
1660
- if (IsMappedKey(key))
1661
- return IndexFromMappedKey(type, key, options);
1662
- return CreateType(IsSchema(key) ? FromSchema(type, IndexPropertyKeys(key)) : FromSchema(type, key), options);
1663
- }
1664
-
1665
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/indexed/indexed-from-mapped-key.mjs
1666
- function MappedIndexPropertyKey(type, key, options) {
1667
- return { [key]: Index(type, [key], Clone(options)) };
1668
- }
1669
- function MappedIndexPropertyKeys(type, propertyKeys, options) {
1670
- return propertyKeys.reduce((result, left) => {
1671
- return { ...result, ...MappedIndexPropertyKey(type, left, options) };
1672
- }, {});
1673
- }
1674
- function MappedIndexProperties(type, mappedKey, options) {
1675
- return MappedIndexPropertyKeys(type, mappedKey.keys, options);
1676
- }
1677
- function IndexFromMappedKey(type, mappedKey, options) {
1678
- const properties = MappedIndexProperties(type, mappedKey, options);
1679
- return MappedResult(properties);
1680
- }
1681
-
1682
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/iterator/iterator.mjs
1683
- function Iterator(items, options) {
1684
- return CreateType({ [Kind]: "Iterator", type: "Iterator", items }, options);
1685
- }
1686
-
1687
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/object/object.mjs
1688
- function RequiredKeys(properties) {
1689
- const keys = [];
1690
- for (let key in properties) {
1691
- if (!IsOptional(properties[key]))
1692
- keys.push(key);
1693
- }
1694
- return keys;
1695
- }
1696
- function _Object(properties, options) {
1697
- const required = RequiredKeys(properties);
1698
- const schematic = required.length > 0 ? { [Kind]: "Object", type: "object", properties, required } : { [Kind]: "Object", type: "object", properties };
1699
- return CreateType(schematic, options);
1700
- }
1701
- var Object2 = _Object;
1702
-
1703
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/promise/promise.mjs
1704
- function Promise2(item, options) {
1705
- return CreateType({ [Kind]: "Promise", type: "Promise", item }, options);
1706
- }
1707
-
1708
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/readonly/readonly.mjs
1709
- function RemoveReadonly(schema) {
1710
- return CreateType(Discard(schema, [ReadonlyKind]));
1711
- }
1712
- function AddReadonly(schema) {
1713
- return CreateType({ ...schema, [ReadonlyKind]: "Readonly" });
1714
- }
1715
- function ReadonlyWithFlag(schema, F) {
1716
- return F === false ? RemoveReadonly(schema) : AddReadonly(schema);
1717
- }
1718
- function Readonly(schema, enable) {
1719
- const F = enable ?? true;
1720
- return IsMappedResult(schema) ? ReadonlyFromMappedResult(schema, F) : ReadonlyWithFlag(schema, F);
1721
- }
1722
-
1723
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/readonly/readonly-from-mapped-result.mjs
1724
- function FromProperties2(K, F) {
1725
- const Acc = {};
1726
- for (const K2 of globalThis.Object.getOwnPropertyNames(K))
1727
- Acc[K2] = Readonly(K[K2], F);
1728
- return Acc;
1729
- }
1730
- function FromMappedResult2(R, F) {
1731
- return FromProperties2(R.properties, F);
1732
- }
1733
- function ReadonlyFromMappedResult(R, F) {
1734
- const P = FromMappedResult2(R, F);
1735
- return MappedResult(P);
1736
- }
1737
-
1738
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/tuple/tuple.mjs
1739
- function Tuple(types, options) {
1740
- 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);
1741
- }
1742
-
1743
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/mapped/mapped.mjs
1744
- function FromMappedResult3(K, P) {
1745
- return K in P ? FromSchemaType(K, P[K]) : MappedResult(P);
1746
- }
1747
- function MappedKeyToKnownMappedResultProperties(K) {
1748
- return { [K]: Literal(K) };
1749
- }
1750
- function MappedKeyToUnknownMappedResultProperties(P) {
1751
- const Acc = {};
1752
- for (const L of P)
1753
- Acc[L] = Literal(L);
1754
- return Acc;
1755
- }
1756
- function MappedKeyToMappedResultProperties(K, P) {
1757
- return SetIncludes(P, K) ? MappedKeyToKnownMappedResultProperties(K) : MappedKeyToUnknownMappedResultProperties(P);
1758
- }
1759
- function FromMappedKey(K, P) {
1760
- const R = MappedKeyToMappedResultProperties(K, P);
1761
- return FromMappedResult3(K, R);
1762
- }
1763
- function FromRest2(K, T) {
1764
- return T.map((L) => FromSchemaType(K, L));
1765
- }
1766
- function FromProperties3(K, T) {
1767
- const Acc = {};
1768
- for (const K2 of globalThis.Object.getOwnPropertyNames(T))
1769
- Acc[K2] = FromSchemaType(K, T[K2]);
1770
- return Acc;
1771
- }
1772
- function FromSchemaType(K, T) {
1773
- const options = { ...T };
1774
- return (
1775
- // unevaluated modifier types
1776
- IsOptional(T) ? Optional(FromSchemaType(K, Discard(T, [OptionalKind]))) : IsReadonly(T) ? Readonly(FromSchemaType(K, Discard(T, [ReadonlyKind]))) : (
1777
- // unevaluated mapped types
1778
- IsMappedResult(T) ? FromMappedResult3(K, T.properties) : IsMappedKey(T) ? FromMappedKey(K, T.keys) : (
1779
- // unevaluated types
1780
- 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
1781
- )
1782
- )
1783
- );
1784
- }
1785
- function MappedFunctionReturnType(K, T) {
1786
- const Acc = {};
1787
- for (const L of K)
1788
- Acc[L] = FromSchemaType(L, T);
1789
- return Acc;
1790
- }
1791
- function Mapped(key, map, options) {
1792
- const K = IsSchema(key) ? IndexPropertyKeys(key) : key;
1793
- const RT = map({ [Kind]: "MappedKey", keys: K });
1794
- const R = MappedFunctionReturnType(K, RT);
1795
- return Object2(R, options);
1796
- }
1797
-
1798
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/optional/optional.mjs
1799
- function RemoveOptional(schema) {
1800
- return CreateType(Discard(schema, [OptionalKind]));
1801
- }
1802
- function AddOptional(schema) {
1803
- return CreateType({ ...schema, [OptionalKind]: "Optional" });
1804
- }
1805
- function OptionalWithFlag(schema, F) {
1806
- return F === false ? RemoveOptional(schema) : AddOptional(schema);
1807
- }
1808
- function Optional(schema, enable) {
1809
- const F = enable ?? true;
1810
- return IsMappedResult(schema) ? OptionalFromMappedResult(schema, F) : OptionalWithFlag(schema, F);
1811
- }
1812
-
1813
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/optional/optional-from-mapped-result.mjs
1814
- function FromProperties4(P, F) {
1815
- const Acc = {};
1816
- for (const K2 of globalThis.Object.getOwnPropertyNames(P))
1817
- Acc[K2] = Optional(P[K2], F);
1818
- return Acc;
1819
- }
1820
- function FromMappedResult4(R, F) {
1821
- return FromProperties4(R.properties, F);
1822
- }
1823
- function OptionalFromMappedResult(R, F) {
1824
- const P = FromMappedResult4(R, F);
1825
- return MappedResult(P);
1826
- }
1827
-
1828
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/intersect/intersect-create.mjs
1829
- function IntersectCreate(T, options = {}) {
1830
- const allObjects = T.every((schema) => IsObject3(schema));
1831
- const clonedUnevaluatedProperties = IsSchema(options.unevaluatedProperties) ? { unevaluatedProperties: options.unevaluatedProperties } : {};
1832
- return CreateType(options.unevaluatedProperties === false || IsSchema(options.unevaluatedProperties) || allObjects ? { ...clonedUnevaluatedProperties, [Kind]: "Intersect", type: "object", allOf: T } : { ...clonedUnevaluatedProperties, [Kind]: "Intersect", allOf: T }, options);
1833
- }
1834
-
1835
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/intersect/intersect-evaluated.mjs
1836
- function IsIntersectOptional(types) {
1837
- return types.every((left) => IsOptional(left));
1838
- }
1839
- function RemoveOptionalFromType2(type) {
1840
- return Discard(type, [OptionalKind]);
1841
- }
1842
- function RemoveOptionalFromRest2(types) {
1843
- return types.map((left) => IsOptional(left) ? RemoveOptionalFromType2(left) : left);
1844
- }
1845
- function ResolveIntersect(types, options) {
1846
- return IsIntersectOptional(types) ? Optional(IntersectCreate(RemoveOptionalFromRest2(types), options)) : IntersectCreate(RemoveOptionalFromRest2(types), options);
1847
- }
1848
- function IntersectEvaluated(types, options = {}) {
1849
- if (types.length === 1)
1850
- return CreateType(types[0], options);
1851
- if (types.length === 0)
1852
- return Never(options);
1853
- if (types.some((schema) => IsTransform(schema)))
1854
- throw new Error("Cannot intersect transform types");
1855
- return ResolveIntersect(types, options);
1856
- }
1857
-
1858
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/intersect/intersect.mjs
1859
- function Intersect(types, options) {
1860
- if (types.length === 1)
1861
- return CreateType(types[0], options);
1862
- if (types.length === 0)
1863
- return Never(options);
1864
- if (types.some((schema) => IsTransform(schema)))
1865
- throw new Error("Cannot intersect transform types");
1866
- return IntersectCreate(types, options);
1867
- }
1868
-
1869
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/ref/ref.mjs
1870
- function Ref(...args) {
1871
- const [$ref, options] = typeof args[0] === "string" ? [args[0], args[1]] : [args[0].$id, args[1]];
1872
- if (typeof $ref !== "string")
1873
- throw new TypeBoxError("Ref: $ref must be a string");
1874
- return CreateType({ [Kind]: "Ref", $ref }, options);
1875
- }
1876
-
1877
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/awaited/awaited.mjs
1878
- function FromComputed(target, parameters) {
1879
- return Computed("Awaited", [Computed(target, parameters)]);
1880
- }
1881
- function FromRef($ref) {
1882
- return Computed("Awaited", [Ref($ref)]);
1883
- }
1884
- function FromIntersect2(types) {
1885
- return Intersect(FromRest3(types));
1886
- }
1887
- function FromUnion4(types) {
1888
- return Union(FromRest3(types));
1889
- }
1890
- function FromPromise(type) {
1891
- return Awaited(type);
1892
- }
1893
- function FromRest3(types) {
1894
- return types.map((type) => Awaited(type));
1895
- }
1896
- function Awaited(type, options) {
1897
- 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);
1898
- }
1899
-
1900
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/keyof/keyof-property-keys.mjs
1901
- function FromRest4(types) {
1902
- const result = [];
1903
- for (const L of types)
1904
- result.push(KeyOfPropertyKeys(L));
1905
- return result;
1906
- }
1907
- function FromIntersect3(types) {
1908
- const propertyKeysArray = FromRest4(types);
1909
- const propertyKeys = SetUnionMany(propertyKeysArray);
1910
- return propertyKeys;
1911
- }
1912
- function FromUnion5(types) {
1913
- const propertyKeysArray = FromRest4(types);
1914
- const propertyKeys = SetIntersectMany(propertyKeysArray);
1915
- return propertyKeys;
1916
- }
1917
- function FromTuple2(types) {
1918
- return types.map((_, indexer) => indexer.toString());
1919
- }
1920
- function FromArray2(_) {
1921
- return ["[number]"];
1922
- }
1923
- function FromProperties5(T) {
1924
- return globalThis.Object.getOwnPropertyNames(T);
1925
- }
1926
- function FromPatternProperties(patternProperties) {
1927
- if (!includePatternProperties)
1928
- return [];
1929
- const patternPropertyKeys = globalThis.Object.getOwnPropertyNames(patternProperties);
1930
- return patternPropertyKeys.map((key) => {
1931
- return key[0] === "^" && key[key.length - 1] === "$" ? key.slice(1, key.length - 1) : key;
1932
- });
1933
- }
1934
- function KeyOfPropertyKeys(type) {
1935
- 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) : [];
1936
- }
1937
- var includePatternProperties = false;
1938
-
1939
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/keyof/keyof.mjs
1940
- function FromComputed2(target, parameters) {
1941
- return Computed("KeyOf", [Computed(target, parameters)]);
1942
- }
1943
- function FromRef2($ref) {
1944
- return Computed("KeyOf", [Ref($ref)]);
1945
- }
1946
- function KeyOfFromType(type, options) {
1947
- const propertyKeys = KeyOfPropertyKeys(type);
1948
- const propertyKeyTypes = KeyOfPropertyKeysToRest(propertyKeys);
1949
- const result = UnionEvaluated(propertyKeyTypes);
1950
- return CreateType(result, options);
1951
- }
1952
- function KeyOfPropertyKeysToRest(propertyKeys) {
1953
- return propertyKeys.map((L) => L === "[number]" ? Number2() : Literal(L));
1954
- }
1955
- function KeyOf(type, options) {
1956
- return IsComputed(type) ? FromComputed2(type.target, type.parameters) : IsRef(type) ? FromRef2(type.$ref) : IsMappedResult(type) ? KeyOfFromMappedResult(type, options) : KeyOfFromType(type, options);
1957
- }
1958
-
1959
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/keyof/keyof-from-mapped-result.mjs
1960
- function FromProperties6(properties, options) {
1961
- const result = {};
1962
- for (const K2 of globalThis.Object.getOwnPropertyNames(properties))
1963
- result[K2] = KeyOf(properties[K2], Clone(options));
1964
- return result;
1965
- }
1966
- function FromMappedResult5(mappedResult, options) {
1967
- return FromProperties6(mappedResult.properties, options);
1968
- }
1969
- function KeyOfFromMappedResult(mappedResult, options) {
1970
- const properties = FromMappedResult5(mappedResult, options);
1971
- return MappedResult(properties);
1972
- }
1973
-
1974
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/composite/composite.mjs
1975
- function CompositeKeys(T) {
1976
- const Acc = [];
1977
- for (const L of T)
1978
- Acc.push(...KeyOfPropertyKeys(L));
1979
- return SetDistinct(Acc);
1980
- }
1981
- function FilterNever(T) {
1982
- return T.filter((L) => !IsNever(L));
1983
- }
1984
- function CompositeProperty(T, K) {
1985
- const Acc = [];
1986
- for (const L of T)
1987
- Acc.push(...IndexFromPropertyKeys(L, [K]));
1988
- return FilterNever(Acc);
1989
- }
1990
- function CompositeProperties(T, K) {
1991
- const Acc = {};
1992
- for (const L of K) {
1993
- Acc[L] = IntersectEvaluated(CompositeProperty(T, L));
1994
- }
1995
- return Acc;
1996
- }
1997
- function Composite(T, options) {
1998
- const K = CompositeKeys(T);
1999
- const P = CompositeProperties(T, K);
2000
- const R = Object2(P, options);
2001
- return R;
2002
- }
2003
-
2004
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/date/date.mjs
2005
- function Date2(options) {
2006
- return CreateType({ [Kind]: "Date", type: "Date" }, options);
2007
- }
2008
-
2009
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/null/null.mjs
2010
- function Null(options) {
2011
- return CreateType({ [Kind]: "Null", type: "null" }, options);
2012
- }
2013
-
2014
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/symbol/symbol.mjs
2015
- function Symbol2(options) {
2016
- return CreateType({ [Kind]: "Symbol", type: "symbol" }, options);
2017
- }
2018
-
2019
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/undefined/undefined.mjs
2020
- function Undefined(options) {
2021
- return CreateType({ [Kind]: "Undefined", type: "undefined" }, options);
2022
- }
2023
-
2024
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/uint8array/uint8array.mjs
2025
- function Uint8Array2(options) {
2026
- return CreateType({ [Kind]: "Uint8Array", type: "Uint8Array" }, options);
2027
- }
2028
-
2029
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/unknown/unknown.mjs
2030
- function Unknown(options) {
2031
- return CreateType({ [Kind]: "Unknown" }, options);
2032
- }
2033
-
2034
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/const/const.mjs
2035
- function FromArray3(T) {
2036
- return T.map((L) => FromValue(L, false));
2037
- }
2038
- function FromProperties7(value) {
2039
- const Acc = {};
2040
- for (const K of globalThis.Object.getOwnPropertyNames(value))
2041
- Acc[K] = Readonly(FromValue(value[K], false));
2042
- return Acc;
2043
- }
2044
- function ConditionalReadonly(T, root) {
2045
- return root === true ? T : Readonly(T);
2046
- }
2047
- function FromValue(value, root) {
2048
- 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({});
2049
- }
2050
- function Const(T, options) {
2051
- return CreateType(FromValue(T, true), options);
2052
- }
2053
-
2054
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/constructor-parameters/constructor-parameters.mjs
2055
- function ConstructorParameters(schema, options) {
2056
- return IsConstructor(schema) ? Tuple(schema.parameters, options) : Never(options);
2057
- }
2058
-
2059
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/enum/enum.mjs
2060
- function Enum(item, options) {
2061
- if (IsUndefined(item))
2062
- throw new Error("Enum undefined or empty");
2063
- const values1 = globalThis.Object.getOwnPropertyNames(item).filter((key) => isNaN(key)).map((key) => item[key]);
2064
- const values2 = [...new Set(values1)];
2065
- const anyOf = values2.map((value) => Literal(value));
2066
- return Union(anyOf, { ...options, [Hint]: "Enum" });
2067
- }
2068
-
2069
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/extends/extends-check.mjs
2070
- var ExtendsResolverError = class extends TypeBoxError {
2071
- };
2072
- var ExtendsResult;
2073
- (function(ExtendsResult2) {
2074
- ExtendsResult2[ExtendsResult2["Union"] = 0] = "Union";
2075
- ExtendsResult2[ExtendsResult2["True"] = 1] = "True";
2076
- ExtendsResult2[ExtendsResult2["False"] = 2] = "False";
2077
- })(ExtendsResult || (ExtendsResult = {}));
2078
- function IntoBooleanResult(result) {
2079
- return result === ExtendsResult.False ? result : ExtendsResult.True;
2080
- }
2081
- function Throw(message) {
2082
- throw new ExtendsResolverError(message);
2083
- }
2084
- function IsStructuralRight(right) {
2085
- return type_exports.IsNever(right) || type_exports.IsIntersect(right) || type_exports.IsUnion(right) || type_exports.IsUnknown(right) || type_exports.IsAny(right);
2086
- }
2087
- function StructuralRight(left, right) {
2088
- 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");
2089
- }
2090
- function FromAnyRight(left, right) {
2091
- return ExtendsResult.True;
2092
- }
2093
- function FromAny(left, right) {
2094
- 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;
2095
- }
2096
- function FromArrayRight(left, right) {
2097
- return type_exports.IsUnknown(left) ? ExtendsResult.False : type_exports.IsAny(left) ? ExtendsResult.Union : type_exports.IsNever(left) ? ExtendsResult.True : ExtendsResult.False;
2098
- }
2099
- function FromArray4(left, right) {
2100
- 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));
2101
- }
2102
- function FromAsyncIterator(left, right) {
2103
- return IsStructuralRight(right) ? StructuralRight(left, right) : !type_exports.IsAsyncIterator(right) ? ExtendsResult.False : IntoBooleanResult(Visit3(left.items, right.items));
2104
- }
2105
- function FromBigInt(left, right) {
2106
- 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;
2107
- }
2108
- function FromBooleanRight(left, right) {
2109
- return type_exports.IsLiteralBoolean(left) ? ExtendsResult.True : type_exports.IsBoolean(left) ? ExtendsResult.True : ExtendsResult.False;
2110
- }
2111
- function FromBoolean(left, right) {
2112
- 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;
2113
- }
2114
- function FromConstructor(left, right) {
2115
- 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, index) => IntoBooleanResult(Visit3(right.parameters[index], schema)) === ExtendsResult.True) ? ExtendsResult.False : IntoBooleanResult(Visit3(left.returns, right.returns));
2116
- }
2117
- function FromDate(left, right) {
2118
- 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;
2119
- }
2120
- function FromFunction(left, right) {
2121
- 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, index) => IntoBooleanResult(Visit3(right.parameters[index], schema)) === ExtendsResult.True) ? ExtendsResult.False : IntoBooleanResult(Visit3(left.returns, right.returns));
2122
- }
2123
- function FromIntegerRight(left, right) {
2124
- return type_exports.IsLiteral(left) && value_exports.IsNumber(left.const) ? ExtendsResult.True : type_exports.IsNumber(left) || type_exports.IsInteger(left) ? ExtendsResult.True : ExtendsResult.False;
2125
- }
2126
- function FromInteger(left, right) {
2127
- 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;
2128
- }
2129
- function FromIntersectRight(left, right) {
2130
- return right.allOf.every((schema) => Visit3(left, schema) === ExtendsResult.True) ? ExtendsResult.True : ExtendsResult.False;
2131
- }
2132
- function FromIntersect4(left, right) {
2133
- return left.allOf.some((schema) => Visit3(schema, right) === ExtendsResult.True) ? ExtendsResult.True : ExtendsResult.False;
2134
- }
2135
- function FromIterator(left, right) {
2136
- return IsStructuralRight(right) ? StructuralRight(left, right) : !type_exports.IsIterator(right) ? ExtendsResult.False : IntoBooleanResult(Visit3(left.items, right.items));
2137
- }
2138
- function FromLiteral2(left, right) {
2139
- 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;
2140
- }
2141
- function FromNeverRight(left, right) {
2142
- return ExtendsResult.False;
2143
- }
2144
- function FromNever(left, right) {
2145
- return ExtendsResult.True;
2146
- }
2147
- function UnwrapTNot(schema) {
2148
- let [current, depth] = [schema, 0];
2149
- while (true) {
2150
- if (!type_exports.IsNot(current))
2151
- break;
2152
- current = current.not;
2153
- depth += 1;
2154
- }
2155
- return depth % 2 === 0 ? current : Unknown();
2156
- }
2157
- function FromNot(left, right) {
2158
- return type_exports.IsNot(left) ? Visit3(UnwrapTNot(left), right) : type_exports.IsNot(right) ? Visit3(left, UnwrapTNot(right)) : Throw("Invalid fallthrough for Not");
2159
- }
2160
- function FromNull(left, right) {
2161
- 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;
2162
- }
2163
- function FromNumberRight(left, right) {
2164
- return type_exports.IsLiteralNumber(left) ? ExtendsResult.True : type_exports.IsNumber(left) || type_exports.IsInteger(left) ? ExtendsResult.True : ExtendsResult.False;
2165
- }
2166
- function FromNumber(left, right) {
2167
- 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;
2168
- }
2169
- function IsObjectPropertyCount(schema, count) {
2170
- return Object.getOwnPropertyNames(schema.properties).length === count;
2171
- }
2172
- function IsObjectStringLike(schema) {
2173
- return IsObjectArrayLike(schema);
2174
- }
2175
- function IsObjectSymbolLike(schema) {
2176
- 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]));
2177
- }
2178
- function IsObjectNumberLike(schema) {
2179
- return IsObjectPropertyCount(schema, 0);
2180
- }
2181
- function IsObjectBooleanLike(schema) {
2182
- return IsObjectPropertyCount(schema, 0);
2183
- }
2184
- function IsObjectBigIntLike(schema) {
2185
- return IsObjectPropertyCount(schema, 0);
2186
- }
2187
- function IsObjectDateLike(schema) {
2188
- return IsObjectPropertyCount(schema, 0);
2189
- }
2190
- function IsObjectUint8ArrayLike(schema) {
2191
- return IsObjectArrayLike(schema);
2192
- }
2193
- function IsObjectFunctionLike(schema) {
2194
- const length = Number2();
2195
- return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "length" in schema.properties && IntoBooleanResult(Visit3(schema.properties["length"], length)) === ExtendsResult.True;
2196
- }
2197
- function IsObjectConstructorLike(schema) {
2198
- return IsObjectPropertyCount(schema, 0);
2199
- }
2200
- function IsObjectArrayLike(schema) {
2201
- const length = Number2();
2202
- return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "length" in schema.properties && IntoBooleanResult(Visit3(schema.properties["length"], length)) === ExtendsResult.True;
2203
- }
2204
- function IsObjectPromiseLike(schema) {
2205
- const then = Function([Any()], Any());
2206
- return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "then" in schema.properties && IntoBooleanResult(Visit3(schema.properties["then"], then)) === ExtendsResult.True;
2207
- }
2208
- function Property(left, right) {
2209
- return Visit3(left, right) === ExtendsResult.False ? ExtendsResult.False : type_exports.IsOptional(left) && !type_exports.IsOptional(right) ? ExtendsResult.False : ExtendsResult.True;
2210
- }
2211
- function FromObjectRight(left, right) {
2212
- 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)) ? (() => {
2213
- return right[Hint] === "Record" ? ExtendsResult.True : ExtendsResult.False;
2214
- })() : type_exports.IsRecord(left) && type_exports.IsNumber(RecordKey(left)) ? (() => {
2215
- return IsObjectPropertyCount(right, 0) ? ExtendsResult.True : ExtendsResult.False;
2216
- })() : ExtendsResult.False;
2217
- }
2218
- function FromObject(left, right) {
2219
- return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : !type_exports.IsObject(right) ? ExtendsResult.False : (() => {
2220
- for (const key of Object.getOwnPropertyNames(right.properties)) {
2221
- if (!(key in left.properties) && !type_exports.IsOptional(right.properties[key])) {
2222
- return ExtendsResult.False;
2223
- }
2224
- if (type_exports.IsOptional(right.properties[key])) {
2225
- return ExtendsResult.True;
2226
- }
2227
- if (Property(left.properties[key], right.properties[key]) === ExtendsResult.False) {
2228
- return ExtendsResult.False;
2229
- }
2230
- }
2231
- return ExtendsResult.True;
2232
- })();
2233
- }
2234
- function FromPromise2(left, right) {
2235
- 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));
2236
- }
2237
- function RecordKey(schema) {
2238
- return PatternNumberExact in schema.patternProperties ? Number2() : PatternStringExact in schema.patternProperties ? String() : Throw("Unknown record key pattern");
2239
- }
2240
- function RecordValue(schema) {
2241
- return PatternNumberExact in schema.patternProperties ? schema.patternProperties[PatternNumberExact] : PatternStringExact in schema.patternProperties ? schema.patternProperties[PatternStringExact] : Throw("Unable to get record value schema");
2242
- }
2243
- function FromRecordRight(left, right) {
2244
- const [Key, Value] = [RecordKey(right), RecordValue(right)];
2245
- 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) ? (() => {
2246
- for (const key of Object.getOwnPropertyNames(left.properties)) {
2247
- if (Property(Value, left.properties[key]) === ExtendsResult.False) {
2248
- return ExtendsResult.False;
2249
- }
2250
- }
2251
- return ExtendsResult.True;
2252
- })() : ExtendsResult.False;
2253
- }
2254
- function FromRecord(left, right) {
2255
- return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : !type_exports.IsRecord(right) ? ExtendsResult.False : Visit3(RecordValue(left), RecordValue(right));
2256
- }
2257
- function FromRegExp(left, right) {
2258
- const L = type_exports.IsRegExp(left) ? String() : left;
2259
- const R = type_exports.IsRegExp(right) ? String() : right;
2260
- return Visit3(L, R);
2261
- }
2262
- function FromStringRight(left, right) {
2263
- return type_exports.IsLiteral(left) && value_exports.IsString(left.const) ? ExtendsResult.True : type_exports.IsString(left) ? ExtendsResult.True : ExtendsResult.False;
2264
- }
2265
- function FromString(left, right) {
2266
- 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;
2267
- }
2268
- function FromSymbol(left, right) {
2269
- 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;
2270
- }
2271
- function FromTemplateLiteral2(left, right) {
2272
- return type_exports.IsTemplateLiteral(left) ? Visit3(TemplateLiteralToUnion(left), right) : type_exports.IsTemplateLiteral(right) ? Visit3(left, TemplateLiteralToUnion(right)) : Throw("Invalid fallthrough for TemplateLiteral");
2273
- }
2274
- function IsArrayOfTuple(left, right) {
2275
- return type_exports.IsArray(right) && left.items !== void 0 && left.items.every((schema) => Visit3(schema, right.items) === ExtendsResult.True);
2276
- }
2277
- function FromTupleRight(left, right) {
2278
- return type_exports.IsNever(left) ? ExtendsResult.True : type_exports.IsUnknown(left) ? ExtendsResult.False : type_exports.IsAny(left) ? ExtendsResult.Union : ExtendsResult.False;
2279
- }
2280
- function FromTuple3(left, right) {
2281
- 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, index) => Visit3(schema, right.items[index]) === ExtendsResult.True) ? ExtendsResult.True : ExtendsResult.False;
2282
- }
2283
- function FromUint8Array(left, right) {
2284
- 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;
2285
- }
2286
- function FromUndefined(left, right) {
2287
- 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;
2288
- }
2289
- function FromUnionRight(left, right) {
2290
- return right.anyOf.some((schema) => Visit3(left, schema) === ExtendsResult.True) ? ExtendsResult.True : ExtendsResult.False;
2291
- }
2292
- function FromUnion6(left, right) {
2293
- return left.anyOf.every((schema) => Visit3(schema, right) === ExtendsResult.True) ? ExtendsResult.True : ExtendsResult.False;
2294
- }
2295
- function FromUnknownRight(left, right) {
2296
- return ExtendsResult.True;
2297
- }
2298
- function FromUnknown(left, right) {
2299
- 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;
2300
- }
2301
- function FromVoidRight(left, right) {
2302
- return type_exports.IsUndefined(left) ? ExtendsResult.True : type_exports.IsUndefined(left) ? ExtendsResult.True : ExtendsResult.False;
2303
- }
2304
- function FromVoid(left, right) {
2305
- 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;
2306
- }
2307
- function Visit3(left, right) {
2308
- return (
2309
- // resolvable
2310
- 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) : (
2311
- // standard
2312
- 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]}'`)
2313
- )
2314
- );
2315
- }
2316
- function ExtendsCheck(left, right) {
2317
- return Visit3(left, right);
2318
- }
2319
-
2320
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/extends/extends-from-mapped-result.mjs
2321
- function FromProperties8(P, Right, True, False, options) {
2322
- const Acc = {};
2323
- for (const K2 of globalThis.Object.getOwnPropertyNames(P))
2324
- Acc[K2] = Extends(P[K2], Right, True, False, Clone(options));
2325
- return Acc;
2326
- }
2327
- function FromMappedResult6(Left, Right, True, False, options) {
2328
- return FromProperties8(Left.properties, Right, True, False, options);
2329
- }
2330
- function ExtendsFromMappedResult(Left, Right, True, False, options) {
2331
- const P = FromMappedResult6(Left, Right, True, False, options);
2332
- return MappedResult(P);
2333
- }
2334
-
2335
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/extends/extends.mjs
2336
- function ExtendsResolve(left, right, trueType, falseType) {
2337
- const R = ExtendsCheck(left, right);
2338
- return R === ExtendsResult.Union ? Union([trueType, falseType]) : R === ExtendsResult.True ? trueType : falseType;
2339
- }
2340
- function Extends(L, R, T, F, options) {
2341
- 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);
2342
- }
2343
-
2344
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/extends/extends-from-mapped-key.mjs
2345
- function FromPropertyKey(K, U, L, R, options) {
2346
- return {
2347
- [K]: Extends(Literal(K), U, L, R, Clone(options))
2348
- };
2349
- }
2350
- function FromPropertyKeys(K, U, L, R, options) {
2351
- return K.reduce((Acc, LK) => {
2352
- return { ...Acc, ...FromPropertyKey(LK, U, L, R, options) };
2353
- }, {});
2354
- }
2355
- function FromMappedKey2(K, U, L, R, options) {
2356
- return FromPropertyKeys(K.keys, U, L, R, options);
2357
- }
2358
- function ExtendsFromMappedKey(T, U, L, R, options) {
2359
- const P = FromMappedKey2(T, U, L, R, options);
2360
- return MappedResult(P);
2361
- }
2362
-
2363
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/exclude/exclude-from-template-literal.mjs
2364
- function ExcludeFromTemplateLiteral(L, R) {
2365
- return Exclude(TemplateLiteralToUnion(L), R);
2366
- }
2367
-
2368
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/exclude/exclude.mjs
2369
- function ExcludeRest(L, R) {
2370
- const excluded = L.filter((inner) => ExtendsCheck(inner, R) === ExtendsResult.False);
2371
- return excluded.length === 1 ? excluded[0] : Union(excluded);
2372
- }
2373
- function Exclude(L, R, options = {}) {
2374
- if (IsTemplateLiteral(L))
2375
- return CreateType(ExcludeFromTemplateLiteral(L, R), options);
2376
- if (IsMappedResult(L))
2377
- return CreateType(ExcludeFromMappedResult(L, R), options);
2378
- return CreateType(IsUnion(L) ? ExcludeRest(L.anyOf, R) : ExtendsCheck(L, R) !== ExtendsResult.False ? Never() : L, options);
2379
- }
2380
-
2381
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/exclude/exclude-from-mapped-result.mjs
2382
- function FromProperties9(P, U) {
2383
- const Acc = {};
2384
- for (const K2 of globalThis.Object.getOwnPropertyNames(P))
2385
- Acc[K2] = Exclude(P[K2], U);
2386
- return Acc;
2387
- }
2388
- function FromMappedResult7(R, T) {
2389
- return FromProperties9(R.properties, T);
2390
- }
2391
- function ExcludeFromMappedResult(R, T) {
2392
- const P = FromMappedResult7(R, T);
2393
- return MappedResult(P);
2394
- }
2395
-
2396
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/extract/extract-from-template-literal.mjs
2397
- function ExtractFromTemplateLiteral(L, R) {
2398
- return Extract(TemplateLiteralToUnion(L), R);
2399
- }
2400
-
2401
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/extract/extract.mjs
2402
- function ExtractRest(L, R) {
2403
- const extracted = L.filter((inner) => ExtendsCheck(inner, R) !== ExtendsResult.False);
2404
- return extracted.length === 1 ? extracted[0] : Union(extracted);
2405
- }
2406
- function Extract(L, R, options) {
2407
- if (IsTemplateLiteral(L))
2408
- return CreateType(ExtractFromTemplateLiteral(L, R), options);
2409
- if (IsMappedResult(L))
2410
- return CreateType(ExtractFromMappedResult(L, R), options);
2411
- return CreateType(IsUnion(L) ? ExtractRest(L.anyOf, R) : ExtendsCheck(L, R) !== ExtendsResult.False ? L : Never(), options);
2412
- }
2413
-
2414
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/extract/extract-from-mapped-result.mjs
2415
- function FromProperties10(P, T) {
2416
- const Acc = {};
2417
- for (const K2 of globalThis.Object.getOwnPropertyNames(P))
2418
- Acc[K2] = Extract(P[K2], T);
2419
- return Acc;
2420
- }
2421
- function FromMappedResult8(R, T) {
2422
- return FromProperties10(R.properties, T);
2423
- }
2424
- function ExtractFromMappedResult(R, T) {
2425
- const P = FromMappedResult8(R, T);
2426
- return MappedResult(P);
2427
- }
2428
-
2429
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/instance-type/instance-type.mjs
2430
- function InstanceType(schema, options) {
2431
- return IsConstructor(schema) ? CreateType(schema.returns, options) : Never(options);
2432
- }
2433
-
2434
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/readonly-optional/readonly-optional.mjs
2435
- function ReadonlyOptional(schema) {
2436
- return Readonly(Optional(schema));
2437
- }
2438
-
2439
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/record/record.mjs
2440
- function RecordCreateFromPattern(pattern, T, options) {
2441
- return CreateType({ [Kind]: "Record", type: "object", patternProperties: { [pattern]: T } }, options);
2442
- }
2443
- function RecordCreateFromKeys(K, T, options) {
2444
- const result = {};
2445
- for (const K2 of K)
2446
- result[K2] = T;
2447
- return Object2(result, { ...options, [Hint]: "Record" });
2448
- }
2449
- function FromTemplateLiteralKey(K, T, options) {
2450
- return IsTemplateLiteralFinite(K) ? RecordCreateFromKeys(IndexPropertyKeys(K), T, options) : RecordCreateFromPattern(K.pattern, T, options);
2451
- }
2452
- function FromUnionKey(key, type, options) {
2453
- return RecordCreateFromKeys(IndexPropertyKeys(Union(key)), type, options);
2454
- }
2455
- function FromLiteralKey(key, type, options) {
2456
- return RecordCreateFromKeys([key.toString()], type, options);
2457
- }
2458
- function FromRegExpKey(key, type, options) {
2459
- return RecordCreateFromPattern(key.source, type, options);
2460
- }
2461
- function FromStringKey(key, type, options) {
2462
- const pattern = IsUndefined(key.pattern) ? PatternStringExact : key.pattern;
2463
- return RecordCreateFromPattern(pattern, type, options);
2464
- }
2465
- function FromAnyKey(_, type, options) {
2466
- return RecordCreateFromPattern(PatternStringExact, type, options);
2467
- }
2468
- function FromNeverKey(_key, type, options) {
2469
- return RecordCreateFromPattern(PatternNeverExact, type, options);
2470
- }
2471
- function FromBooleanKey(_key, type, options) {
2472
- return Object2({ true: type, false: type }, options);
2473
- }
2474
- function FromIntegerKey(_key, type, options) {
2475
- return RecordCreateFromPattern(PatternNumberExact, type, options);
2476
- }
2477
- function FromNumberKey(_, type, options) {
2478
- return RecordCreateFromPattern(PatternNumberExact, type, options);
2479
- }
2480
- function Record(key, type, options = {}) {
2481
- 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);
2482
- }
2483
- function RecordPattern(record) {
2484
- return globalThis.Object.getOwnPropertyNames(record.patternProperties)[0];
2485
- }
2486
- function RecordKey2(type) {
2487
- const pattern = RecordPattern(type);
2488
- return pattern === PatternStringExact ? String() : pattern === PatternNumberExact ? Number2() : String({ pattern });
2489
- }
2490
- function RecordValue2(type) {
2491
- return type.patternProperties[RecordPattern(type)];
2492
- }
2493
-
2494
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/instantiate/instantiate.mjs
2495
- function FromConstructor2(args, type) {
2496
- type.parameters = FromTypes(args, type.parameters);
2497
- type.returns = FromType(args, type.returns);
2498
- return type;
2499
- }
2500
- function FromFunction2(args, type) {
2501
- type.parameters = FromTypes(args, type.parameters);
2502
- type.returns = FromType(args, type.returns);
2503
- return type;
2504
- }
2505
- function FromIntersect5(args, type) {
2506
- type.allOf = FromTypes(args, type.allOf);
2507
- return type;
2508
- }
2509
- function FromUnion7(args, type) {
2510
- type.anyOf = FromTypes(args, type.anyOf);
2511
- return type;
2512
- }
2513
- function FromTuple4(args, type) {
2514
- if (IsUndefined(type.items))
2515
- return type;
2516
- type.items = FromTypes(args, type.items);
2517
- return type;
2518
- }
2519
- function FromArray5(args, type) {
2520
- type.items = FromType(args, type.items);
2521
- return type;
2522
- }
2523
- function FromAsyncIterator2(args, type) {
2524
- type.items = FromType(args, type.items);
2525
- return type;
2526
- }
2527
- function FromIterator2(args, type) {
2528
- type.items = FromType(args, type.items);
2529
- return type;
2530
- }
2531
- function FromPromise3(args, type) {
2532
- type.item = FromType(args, type.item);
2533
- return type;
2534
- }
2535
- function FromObject2(args, type) {
2536
- const mappedProperties = FromProperties11(args, type.properties);
2537
- return { ...type, ...Object2(mappedProperties) };
2538
- }
2539
- function FromRecord2(args, type) {
2540
- const mappedKey = FromType(args, RecordKey2(type));
2541
- const mappedValue = FromType(args, RecordValue2(type));
2542
- const result = Record(mappedKey, mappedValue);
2543
- return { ...type, ...result };
2544
- }
2545
- function FromArgument(args, argument) {
2546
- return argument.index in args ? args[argument.index] : Unknown();
2547
- }
2548
- function FromProperty2(args, type) {
2549
- const isReadonly = IsReadonly(type);
2550
- const isOptional = IsOptional(type);
2551
- const mapped = FromType(args, type);
2552
- return isReadonly && isOptional ? ReadonlyOptional(mapped) : isReadonly && !isOptional ? Readonly(mapped) : !isReadonly && isOptional ? Optional(mapped) : mapped;
2553
- }
2554
- function FromProperties11(args, properties) {
2555
- return globalThis.Object.getOwnPropertyNames(properties).reduce((result, key) => {
2556
- return { ...result, [key]: FromProperty2(args, properties[key]) };
2557
- }, {});
2558
- }
2559
- function FromTypes(args, types) {
2560
- return types.map((type) => FromType(args, type));
2561
- }
2562
- function FromType(args, type) {
2563
- 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;
2564
- }
2565
- function Instantiate(type, args) {
2566
- return FromType(args, CloneType(type));
2567
- }
2568
-
2569
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/integer/integer.mjs
2570
- function Integer(options) {
2571
- return CreateType({ [Kind]: "Integer", type: "integer" }, options);
2572
- }
2573
-
2574
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/intrinsic/intrinsic-from-mapped-key.mjs
2575
- function MappedIntrinsicPropertyKey(K, M, options) {
2576
- return {
2577
- [K]: Intrinsic(Literal(K), M, Clone(options))
2578
- };
2579
- }
2580
- function MappedIntrinsicPropertyKeys(K, M, options) {
2581
- const result = K.reduce((Acc, L) => {
2582
- return { ...Acc, ...MappedIntrinsicPropertyKey(L, M, options) };
2583
- }, {});
2584
- return result;
2585
- }
2586
- function MappedIntrinsicProperties(T, M, options) {
2587
- return MappedIntrinsicPropertyKeys(T["keys"], M, options);
2588
- }
2589
- function IntrinsicFromMappedKey(T, M, options) {
2590
- const P = MappedIntrinsicProperties(T, M, options);
2591
- return MappedResult(P);
2592
- }
2593
-
2594
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/intrinsic/intrinsic.mjs
2595
- function ApplyUncapitalize(value) {
2596
- const [first, rest] = [value.slice(0, 1), value.slice(1)];
2597
- return [first.toLowerCase(), rest].join("");
2598
- }
2599
- function ApplyCapitalize(value) {
2600
- const [first, rest] = [value.slice(0, 1), value.slice(1)];
2601
- return [first.toUpperCase(), rest].join("");
2602
- }
2603
- function ApplyUppercase(value) {
2604
- return value.toUpperCase();
2605
- }
2606
- function ApplyLowercase(value) {
2607
- return value.toLowerCase();
2608
- }
2609
- function FromTemplateLiteral3(schema, mode, options) {
2610
- const expression = TemplateLiteralParseExact(schema.pattern);
2611
- const finite = IsTemplateLiteralExpressionFinite(expression);
2612
- if (!finite)
2613
- return { ...schema, pattern: FromLiteralValue(schema.pattern, mode) };
2614
- const strings = [...TemplateLiteralExpressionGenerate(expression)];
2615
- const literals = strings.map((value) => Literal(value));
2616
- const mapped = FromRest5(literals, mode);
2617
- const union = Union(mapped);
2618
- return TemplateLiteral([union], options);
2619
- }
2620
- function FromLiteralValue(value, mode) {
2621
- return typeof value === "string" ? mode === "Uncapitalize" ? ApplyUncapitalize(value) : mode === "Capitalize" ? ApplyCapitalize(value) : mode === "Uppercase" ? ApplyUppercase(value) : mode === "Lowercase" ? ApplyLowercase(value) : value : value.toString();
2622
- }
2623
- function FromRest5(T, M) {
2624
- return T.map((L) => Intrinsic(L, M));
2625
- }
2626
- function Intrinsic(schema, mode, options = {}) {
2627
- return (
2628
- // Intrinsic-Mapped-Inference
2629
- IsMappedKey(schema) ? IntrinsicFromMappedKey(schema, mode, options) : (
2630
- // Standard-Inference
2631
- IsTemplateLiteral(schema) ? FromTemplateLiteral3(schema, mode, options) : IsUnion(schema) ? Union(FromRest5(schema.anyOf, mode), options) : IsLiteral(schema) ? Literal(FromLiteralValue(schema.const, mode), options) : (
2632
- // Default Type
2633
- CreateType(schema, options)
2634
- )
2635
- )
2636
- );
2637
- }
2638
-
2639
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/intrinsic/capitalize.mjs
2640
- function Capitalize(T, options = {}) {
2641
- return Intrinsic(T, "Capitalize", options);
2642
- }
2643
-
2644
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/intrinsic/lowercase.mjs
2645
- function Lowercase(T, options = {}) {
2646
- return Intrinsic(T, "Lowercase", options);
2647
- }
2648
-
2649
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/intrinsic/uncapitalize.mjs
2650
- function Uncapitalize(T, options = {}) {
2651
- return Intrinsic(T, "Uncapitalize", options);
2652
- }
2653
-
2654
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/intrinsic/uppercase.mjs
2655
- function Uppercase(T, options = {}) {
2656
- return Intrinsic(T, "Uppercase", options);
2657
- }
2658
-
2659
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/omit/omit-from-mapped-result.mjs
2660
- function FromProperties12(properties, propertyKeys, options) {
2661
- const result = {};
2662
- for (const K2 of globalThis.Object.getOwnPropertyNames(properties))
2663
- result[K2] = Omit(properties[K2], propertyKeys, Clone(options));
2664
- return result;
2665
- }
2666
- function FromMappedResult9(mappedResult, propertyKeys, options) {
2667
- return FromProperties12(mappedResult.properties, propertyKeys, options);
2668
- }
2669
- function OmitFromMappedResult(mappedResult, propertyKeys, options) {
2670
- const properties = FromMappedResult9(mappedResult, propertyKeys, options);
2671
- return MappedResult(properties);
2672
- }
2673
-
2674
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/omit/omit.mjs
2675
- function FromIntersect6(types, propertyKeys) {
2676
- return types.map((type) => OmitResolve(type, propertyKeys));
2677
- }
2678
- function FromUnion8(types, propertyKeys) {
2679
- return types.map((type) => OmitResolve(type, propertyKeys));
2680
- }
2681
- function FromProperty3(properties, key) {
2682
- const { [key]: _, ...R } = properties;
2683
- return R;
2684
- }
2685
- function FromProperties13(properties, propertyKeys) {
2686
- return propertyKeys.reduce((T, K2) => FromProperty3(T, K2), properties);
2687
- }
2688
- function FromObject3(properties, propertyKeys) {
2689
- const options = Discard(properties, [TransformKind, "$id", "required", "properties"]);
2690
- const omittedProperties = FromProperties13(properties["properties"], propertyKeys);
2691
- return Object2(omittedProperties, options);
2692
- }
2693
- function UnionFromPropertyKeys(propertyKeys) {
2694
- const result = propertyKeys.reduce((result2, key) => IsLiteralValue(key) ? [...result2, Literal(key)] : result2, []);
2695
- return Union(result);
2696
- }
2697
- function OmitResolve(properties, propertyKeys) {
2698
- return IsIntersect(properties) ? Intersect(FromIntersect6(properties.allOf, propertyKeys)) : IsUnion(properties) ? Union(FromUnion8(properties.anyOf, propertyKeys)) : IsObject3(properties) ? FromObject3(properties, propertyKeys) : Object2({});
2699
- }
2700
- function Omit(type, key, options) {
2701
- const typeKey = IsArray(key) ? UnionFromPropertyKeys(key) : key;
2702
- const propertyKeys = IsSchema(key) ? IndexPropertyKeys(key) : key;
2703
- const isTypeRef = IsRef(type);
2704
- const isKeyRef = IsRef(key);
2705
- 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 });
2706
- }
2707
-
2708
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/omit/omit-from-mapped-key.mjs
2709
- function FromPropertyKey2(type, key, options) {
2710
- return { [key]: Omit(type, [key], Clone(options)) };
2711
- }
2712
- function FromPropertyKeys2(type, propertyKeys, options) {
2713
- return propertyKeys.reduce((Acc, LK) => {
2714
- return { ...Acc, ...FromPropertyKey2(type, LK, options) };
2715
- }, {});
2716
- }
2717
- function FromMappedKey3(type, mappedKey, options) {
2718
- return FromPropertyKeys2(type, mappedKey.keys, options);
2719
- }
2720
- function OmitFromMappedKey(type, mappedKey, options) {
2721
- const properties = FromMappedKey3(type, mappedKey, options);
2722
- return MappedResult(properties);
2723
- }
2724
-
2725
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/pick/pick-from-mapped-result.mjs
2726
- function FromProperties14(properties, propertyKeys, options) {
2727
- const result = {};
2728
- for (const K2 of globalThis.Object.getOwnPropertyNames(properties))
2729
- result[K2] = Pick(properties[K2], propertyKeys, Clone(options));
2730
- return result;
2731
- }
2732
- function FromMappedResult10(mappedResult, propertyKeys, options) {
2733
- return FromProperties14(mappedResult.properties, propertyKeys, options);
2734
- }
2735
- function PickFromMappedResult(mappedResult, propertyKeys, options) {
2736
- const properties = FromMappedResult10(mappedResult, propertyKeys, options);
2737
- return MappedResult(properties);
2738
- }
2739
-
2740
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/pick/pick.mjs
2741
- function FromIntersect7(types, propertyKeys) {
2742
- return types.map((type) => PickResolve(type, propertyKeys));
2743
- }
2744
- function FromUnion9(types, propertyKeys) {
2745
- return types.map((type) => PickResolve(type, propertyKeys));
2746
- }
2747
- function FromProperties15(properties, propertyKeys) {
2748
- const result = {};
2749
- for (const K2 of propertyKeys)
2750
- if (K2 in properties)
2751
- result[K2] = properties[K2];
2752
- return result;
2753
- }
2754
- function FromObject4(T, K) {
2755
- const options = Discard(T, [TransformKind, "$id", "required", "properties"]);
2756
- const properties = FromProperties15(T["properties"], K);
2757
- return Object2(properties, options);
2758
- }
2759
- function UnionFromPropertyKeys2(propertyKeys) {
2760
- const result = propertyKeys.reduce((result2, key) => IsLiteralValue(key) ? [...result2, Literal(key)] : result2, []);
2761
- return Union(result);
2762
- }
2763
- function PickResolve(properties, propertyKeys) {
2764
- return IsIntersect(properties) ? Intersect(FromIntersect7(properties.allOf, propertyKeys)) : IsUnion(properties) ? Union(FromUnion9(properties.anyOf, propertyKeys)) : IsObject3(properties) ? FromObject4(properties, propertyKeys) : Object2({});
2765
- }
2766
- function Pick(type, key, options) {
2767
- const typeKey = IsArray(key) ? UnionFromPropertyKeys2(key) : key;
2768
- const propertyKeys = IsSchema(key) ? IndexPropertyKeys(key) : key;
2769
- const isTypeRef = IsRef(type);
2770
- const isKeyRef = IsRef(key);
2771
- 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 });
2772
- }
2773
-
2774
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/pick/pick-from-mapped-key.mjs
2775
- function FromPropertyKey3(type, key, options) {
2776
- return {
2777
- [key]: Pick(type, [key], Clone(options))
2778
- };
2779
- }
2780
- function FromPropertyKeys3(type, propertyKeys, options) {
2781
- return propertyKeys.reduce((result, leftKey) => {
2782
- return { ...result, ...FromPropertyKey3(type, leftKey, options) };
2783
- }, {});
2784
- }
2785
- function FromMappedKey4(type, mappedKey, options) {
2786
- return FromPropertyKeys3(type, mappedKey.keys, options);
2787
- }
2788
- function PickFromMappedKey(type, mappedKey, options) {
2789
- const properties = FromMappedKey4(type, mappedKey, options);
2790
- return MappedResult(properties);
2791
- }
2792
-
2793
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/partial/partial.mjs
2794
- function FromComputed3(target, parameters) {
2795
- return Computed("Partial", [Computed(target, parameters)]);
2796
- }
2797
- function FromRef3($ref) {
2798
- return Computed("Partial", [Ref($ref)]);
2799
- }
2800
- function FromProperties16(properties) {
2801
- const partialProperties = {};
2802
- for (const K of globalThis.Object.getOwnPropertyNames(properties))
2803
- partialProperties[K] = Optional(properties[K]);
2804
- return partialProperties;
2805
- }
2806
- function FromObject5(type) {
2807
- const options = Discard(type, [TransformKind, "$id", "required", "properties"]);
2808
- const properties = FromProperties16(type["properties"]);
2809
- return Object2(properties, options);
2810
- }
2811
- function FromRest6(types) {
2812
- return types.map((type) => PartialResolve(type));
2813
- }
2814
- function PartialResolve(type) {
2815
- return (
2816
- // Mappable
2817
- 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) : (
2818
- // Intrinsic
2819
- 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 : (
2820
- // Passthrough
2821
- Object2({})
2822
- )
2823
- )
2824
- );
2825
- }
2826
- function Partial(type, options) {
2827
- if (IsMappedResult(type)) {
2828
- return PartialFromMappedResult(type, options);
2829
- } else {
2830
- return CreateType({ ...PartialResolve(type), ...options });
2831
- }
2832
- }
2833
-
2834
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/partial/partial-from-mapped-result.mjs
2835
- function FromProperties17(K, options) {
2836
- const Acc = {};
2837
- for (const K2 of globalThis.Object.getOwnPropertyNames(K))
2838
- Acc[K2] = Partial(K[K2], Clone(options));
2839
- return Acc;
2840
- }
2841
- function FromMappedResult11(R, options) {
2842
- return FromProperties17(R.properties, options);
2843
- }
2844
- function PartialFromMappedResult(R, options) {
2845
- const P = FromMappedResult11(R, options);
2846
- return MappedResult(P);
2847
- }
2848
-
2849
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/required/required.mjs
2850
- function FromComputed4(target, parameters) {
2851
- return Computed("Required", [Computed(target, parameters)]);
2852
- }
2853
- function FromRef4($ref) {
2854
- return Computed("Required", [Ref($ref)]);
2855
- }
2856
- function FromProperties18(properties) {
2857
- const requiredProperties = {};
2858
- for (const K of globalThis.Object.getOwnPropertyNames(properties))
2859
- requiredProperties[K] = Discard(properties[K], [OptionalKind]);
2860
- return requiredProperties;
2861
- }
2862
- function FromObject6(type) {
2863
- const options = Discard(type, [TransformKind, "$id", "required", "properties"]);
2864
- const properties = FromProperties18(type["properties"]);
2865
- return Object2(properties, options);
2866
- }
2867
- function FromRest7(types) {
2868
- return types.map((type) => RequiredResolve(type));
2869
- }
2870
- function RequiredResolve(type) {
2871
- return (
2872
- // Mappable
2873
- 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) : (
2874
- // Intrinsic
2875
- 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 : (
2876
- // Passthrough
2877
- Object2({})
2878
- )
2879
- )
2880
- );
2881
- }
2882
- function Required(type, options) {
2883
- if (IsMappedResult(type)) {
2884
- return RequiredFromMappedResult(type, options);
2885
- } else {
2886
- return CreateType({ ...RequiredResolve(type), ...options });
2887
- }
2888
- }
2889
-
2890
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/required/required-from-mapped-result.mjs
2891
- function FromProperties19(P, options) {
2892
- const Acc = {};
2893
- for (const K2 of globalThis.Object.getOwnPropertyNames(P))
2894
- Acc[K2] = Required(P[K2], options);
2895
- return Acc;
2896
- }
2897
- function FromMappedResult12(R, options) {
2898
- return FromProperties19(R.properties, options);
2899
- }
2900
- function RequiredFromMappedResult(R, options) {
2901
- const P = FromMappedResult12(R, options);
2902
- return MappedResult(P);
2903
- }
2904
-
2905
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/module/compute.mjs
2906
- function DereferenceParameters(moduleProperties, types) {
2907
- return types.map((type) => {
2908
- return IsRef(type) ? Dereference(moduleProperties, type.$ref) : FromType2(moduleProperties, type);
2909
- });
2910
- }
2911
- function Dereference(moduleProperties, ref) {
2912
- return ref in moduleProperties ? IsRef(moduleProperties[ref]) ? Dereference(moduleProperties, moduleProperties[ref].$ref) : FromType2(moduleProperties, moduleProperties[ref]) : Never();
2913
- }
2914
- function FromAwaited(parameters) {
2915
- return Awaited(parameters[0]);
2916
- }
2917
- function FromIndex(parameters) {
2918
- return Index(parameters[0], parameters[1]);
2919
- }
2920
- function FromKeyOf(parameters) {
2921
- return KeyOf(parameters[0]);
2922
- }
2923
- function FromPartial(parameters) {
2924
- return Partial(parameters[0]);
2925
- }
2926
- function FromOmit(parameters) {
2927
- return Omit(parameters[0], parameters[1]);
2928
- }
2929
- function FromPick(parameters) {
2930
- return Pick(parameters[0], parameters[1]);
2931
- }
2932
- function FromRequired(parameters) {
2933
- return Required(parameters[0]);
2934
- }
2935
- function FromComputed5(moduleProperties, target, parameters) {
2936
- const dereferenced = DereferenceParameters(moduleProperties, parameters);
2937
- 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();
2938
- }
2939
- function FromArray6(moduleProperties, type) {
2940
- return Array2(FromType2(moduleProperties, type));
2941
- }
2942
- function FromAsyncIterator3(moduleProperties, type) {
2943
- return AsyncIterator(FromType2(moduleProperties, type));
2944
- }
2945
- function FromConstructor3(moduleProperties, parameters, instanceType) {
2946
- return Constructor(FromTypes2(moduleProperties, parameters), FromType2(moduleProperties, instanceType));
2947
- }
2948
- function FromFunction3(moduleProperties, parameters, returnType) {
2949
- return Function(FromTypes2(moduleProperties, parameters), FromType2(moduleProperties, returnType));
2950
- }
2951
- function FromIntersect8(moduleProperties, types) {
2952
- return Intersect(FromTypes2(moduleProperties, types));
2953
- }
2954
- function FromIterator3(moduleProperties, type) {
2955
- return Iterator(FromType2(moduleProperties, type));
2956
- }
2957
- function FromObject7(moduleProperties, properties) {
2958
- return Object2(globalThis.Object.keys(properties).reduce((result, key) => {
2959
- return { ...result, [key]: FromType2(moduleProperties, properties[key]) };
2960
- }, {}));
2961
- }
2962
- function FromRecord3(moduleProperties, type) {
2963
- const [value, pattern] = [FromType2(moduleProperties, RecordValue2(type)), RecordPattern(type)];
2964
- const result = CloneType(type);
2965
- result.patternProperties[pattern] = value;
2966
- return result;
2967
- }
2968
- function FromTransform(moduleProperties, transform) {
2969
- return IsRef(transform) ? { ...Dereference(moduleProperties, transform.$ref), [TransformKind]: transform[TransformKind] } : transform;
2970
- }
2971
- function FromTuple5(moduleProperties, types) {
2972
- return Tuple(FromTypes2(moduleProperties, types));
2973
- }
2974
- function FromUnion10(moduleProperties, types) {
2975
- return Union(FromTypes2(moduleProperties, types));
2976
- }
2977
- function FromTypes2(moduleProperties, types) {
2978
- return types.map((type) => FromType2(moduleProperties, type));
2979
- }
2980
- function FromType2(moduleProperties, type) {
2981
- return (
2982
- // Modifiers
2983
- IsOptional(type) ? CreateType(FromType2(moduleProperties, Discard(type, [OptionalKind])), type) : IsReadonly(type) ? CreateType(FromType2(moduleProperties, Discard(type, [ReadonlyKind])), type) : (
2984
- // Transform
2985
- IsTransform(type) ? CreateType(FromTransform(moduleProperties, type), type) : (
2986
- // Types
2987
- 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
2988
- )
2989
- )
2990
- );
2991
- }
2992
- function ComputeType(moduleProperties, key) {
2993
- return key in moduleProperties ? FromType2(moduleProperties, moduleProperties[key]) : Never();
2994
- }
2995
- function ComputeModuleProperties(moduleProperties) {
2996
- return globalThis.Object.getOwnPropertyNames(moduleProperties).reduce((result, key) => {
2997
- return { ...result, [key]: ComputeType(moduleProperties, key) };
2998
- }, {});
2999
- }
3000
-
3001
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/module/module.mjs
3002
- var TModule = class {
3003
- constructor($defs) {
3004
- const computed = ComputeModuleProperties($defs);
3005
- const identified = this.WithIdentifiers(computed);
3006
- this.$defs = identified;
3007
- }
3008
- /** `[Json]` Imports a Type by Key. */
3009
- Import(key, options) {
3010
- const $defs = { ...this.$defs, [key]: CreateType(this.$defs[key], options) };
3011
- return CreateType({ [Kind]: "Import", $defs, $ref: key });
3012
- }
3013
- // prettier-ignore
3014
- WithIdentifiers($defs) {
3015
- return globalThis.Object.getOwnPropertyNames($defs).reduce((result, key) => {
3016
- return { ...result, [key]: { ...$defs[key], $id: key } };
3017
- }, {});
3018
- }
3019
- };
3020
- function Module(properties) {
3021
- return new TModule(properties);
3022
- }
3023
-
3024
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/not/not.mjs
3025
- function Not(type, options) {
3026
- return CreateType({ [Kind]: "Not", not: type }, options);
3027
- }
3028
-
3029
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/parameters/parameters.mjs
3030
- function Parameters(schema, options) {
3031
- return IsFunction2(schema) ? Tuple(schema.parameters, options) : Never();
3032
- }
3033
-
3034
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/recursive/recursive.mjs
3035
- var Ordinal = 0;
3036
- function Recursive(callback, options = {}) {
3037
- if (IsUndefined(options.$id))
3038
- options.$id = `T${Ordinal++}`;
3039
- const thisType = CloneType(callback({ [Kind]: "This", $ref: `${options.$id}` }));
3040
- thisType.$id = options.$id;
3041
- return CreateType({ [Hint]: "Recursive", ...thisType }, options);
3042
- }
3043
-
3044
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/regexp/regexp.mjs
3045
- function RegExp2(unresolved, options) {
3046
- const expr = IsString(unresolved) ? new globalThis.RegExp(unresolved) : unresolved;
3047
- return CreateType({ [Kind]: "RegExp", type: "RegExp", source: expr.source, flags: expr.flags }, options);
3048
- }
3049
-
3050
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/rest/rest.mjs
3051
- function RestResolve(T) {
3052
- return IsIntersect(T) ? T.allOf : IsUnion(T) ? T.anyOf : IsTuple(T) ? T.items ?? [] : [];
3053
- }
3054
- function Rest(T) {
3055
- return RestResolve(T);
3056
- }
3057
-
3058
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/return-type/return-type.mjs
3059
- function ReturnType(schema, options) {
3060
- return IsFunction2(schema) ? CreateType(schema.returns, options) : Never(options);
3061
- }
3062
-
3063
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/transform/transform.mjs
3064
- var TransformDecodeBuilder = class {
3065
- constructor(schema) {
3066
- this.schema = schema;
3067
- }
3068
- Decode(decode) {
3069
- return new TransformEncodeBuilder(this.schema, decode);
3070
- }
3071
- };
3072
- var TransformEncodeBuilder = class {
3073
- constructor(schema, decode) {
3074
- this.schema = schema;
3075
- this.decode = decode;
3076
- }
3077
- EncodeTransform(encode, schema) {
3078
- const Encode = (value) => schema[TransformKind].Encode(encode(value));
3079
- const Decode = (value) => this.decode(schema[TransformKind].Decode(value));
3080
- const Codec = { Encode, Decode };
3081
- return { ...schema, [TransformKind]: Codec };
3082
- }
3083
- EncodeSchema(encode, schema) {
3084
- const Codec = { Decode: this.decode, Encode: encode };
3085
- return { ...schema, [TransformKind]: Codec };
3086
- }
3087
- Encode(encode) {
3088
- return IsTransform(this.schema) ? this.EncodeTransform(encode, this.schema) : this.EncodeSchema(encode, this.schema);
3089
- }
3090
- };
3091
- function Transform(schema) {
3092
- return new TransformDecodeBuilder(schema);
3093
- }
3094
-
3095
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/unsafe/unsafe.mjs
3096
- function Unsafe(options = {}) {
3097
- return CreateType({ [Kind]: options[Kind] ?? "Unsafe" }, options);
3098
- }
3099
-
3100
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/void/void.mjs
3101
- function Void(options) {
3102
- return CreateType({ [Kind]: "Void", type: "void" }, options);
3103
- }
3104
-
3105
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/type/type.mjs
3106
- var type_exports2 = {};
3107
- __export(type_exports2, {
3108
- Any: () => Any,
3109
- Argument: () => Argument,
3110
- Array: () => Array2,
3111
- AsyncIterator: () => AsyncIterator,
3112
- Awaited: () => Awaited,
3113
- BigInt: () => BigInt,
3114
- Boolean: () => Boolean,
3115
- Capitalize: () => Capitalize,
3116
- Composite: () => Composite,
3117
- Const: () => Const,
3118
- Constructor: () => Constructor,
3119
- ConstructorParameters: () => ConstructorParameters,
3120
- Date: () => Date2,
3121
- Enum: () => Enum,
3122
- Exclude: () => Exclude,
3123
- Extends: () => Extends,
3124
- Extract: () => Extract,
3125
- Function: () => Function,
3126
- Index: () => Index,
3127
- InstanceType: () => InstanceType,
3128
- Instantiate: () => Instantiate,
3129
- Integer: () => Integer,
3130
- Intersect: () => Intersect,
3131
- Iterator: () => Iterator,
3132
- KeyOf: () => KeyOf,
3133
- Literal: () => Literal,
3134
- Lowercase: () => Lowercase,
3135
- Mapped: () => Mapped,
3136
- Module: () => Module,
3137
- Never: () => Never,
3138
- Not: () => Not,
3139
- Null: () => Null,
3140
- Number: () => Number2,
3141
- Object: () => Object2,
3142
- Omit: () => Omit,
3143
- Optional: () => Optional,
3144
- Parameters: () => Parameters,
3145
- Partial: () => Partial,
3146
- Pick: () => Pick,
3147
- Promise: () => Promise2,
3148
- Readonly: () => Readonly,
3149
- ReadonlyOptional: () => ReadonlyOptional,
3150
- Record: () => Record,
3151
- Recursive: () => Recursive,
3152
- Ref: () => Ref,
3153
- RegExp: () => RegExp2,
3154
- Required: () => Required,
3155
- Rest: () => Rest,
3156
- ReturnType: () => ReturnType,
3157
- String: () => String,
3158
- Symbol: () => Symbol2,
3159
- TemplateLiteral: () => TemplateLiteral,
3160
- Transform: () => Transform,
3161
- Tuple: () => Tuple,
3162
- Uint8Array: () => Uint8Array2,
3163
- Uncapitalize: () => Uncapitalize,
3164
- Undefined: () => Undefined,
3165
- Union: () => Union,
3166
- Unknown: () => Unknown,
3167
- Unsafe: () => Unsafe,
3168
- Uppercase: () => Uppercase,
3169
- Void: () => Void
3170
- });
3171
-
3172
- // ../../node_modules/.pnpm/@sinclair+typebox@0.34.41/node_modules/@sinclair/typebox/build/esm/type/type/index.mjs
3173
- var Type = type_exports2;
3174
-
3175
- // src/lib/types/schemas.ts
3176
- var SuccessResponseSchema = (dataSchema) => Type.Object(
3177
- {
3178
- success: Type.Literal(true),
3179
- data: dataSchema,
3180
- message: Type.Optional(Type.String())
3181
- }
3182
- );
3183
- var ErrorResponseSchema = Type.Object(
3184
- {
3185
- success: Type.Literal(false),
3186
- error: Type.Object(
3187
- {
3188
- code: Type.String(),
3189
- message: Type.String(),
3190
- details: Type.Optional(Type.Any())
3191
- }
3192
- )
3193
- }
3194
- );
3195
- var ApiResponseSchema = (dataSchema) => Type.Union([
3196
- SuccessResponseSchema(dataSchema),
3197
- ErrorResponseSchema
3198
- ]);
3199
-
3200
- // src/lib/contracts/auth.ts
3201
- var EMAIL_PATTERN = "^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$";
3202
- var PHONE_PATTERN = "^\\+[1-9]\\d{1,14}$";
3203
- var FINGERPRINT_PATTERN = "^[a-f0-9]{64}$";
3204
- var UUID_PATTERN = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
3205
- var BASE64_PATTERN = "^[A-Za-z0-9+/]+=*$";
3206
- var sendVerificationCodeContract = {
3207
- method: "POST",
3208
- path: "/_auth/codes",
3209
- body: Type.Object({
3210
- target: Type.String({
3211
- description: "Email address or phone number in E.164 format"
3212
- }),
3213
- targetType: Type.Union([
3214
- Type.Literal("email"),
3215
- Type.Literal("phone")
3216
- ], {
3217
- description: "Type of target (email or phone)"
3218
- }),
3219
- purpose: Type.Union([
3220
- Type.Literal("registration"),
3221
- Type.Literal("login"),
3222
- Type.Literal("password_reset")
3223
- ], {
3224
- description: "Purpose of verification"
3225
- })
3226
- }),
3227
- response: ApiResponseSchema(
3228
- Type.Object({
3229
- success: Type.Boolean(),
3230
- expiresAt: Type.String({ description: "ISO 8601 expiry time" })
3231
- })
3232
- )
3233
- };
3234
- var verifyCodeContract = {
3235
- method: "POST",
3236
- path: "/_auth/codes/verify",
3237
- body: Type.Object({
3238
- target: Type.String({
3239
- description: "Email address or phone number"
3240
- }),
3241
- targetType: Type.Union([
3242
- Type.Literal("email"),
3243
- Type.Literal("phone")
3244
- ]),
3245
- code: Type.String({
3246
- minLength: 6,
3247
- maxLength: 6,
3248
- pattern: "^[0-9]{6}$",
3249
- description: "6-digit verification code"
3250
- }),
3251
- purpose: Type.Union([
3252
- Type.Literal("registration"),
3253
- Type.Literal("login"),
3254
- Type.Literal("password_reset")
3255
- ])
3256
- }),
3257
- response: ApiResponseSchema(
3258
- Type.Object({
3259
- valid: Type.Boolean(),
3260
- verificationToken: Type.Optional(Type.String({
3261
- description: "Temporary token for completing registration (15min validity)"
3262
- }))
3263
- })
3264
- )
3265
- };
3266
- var checkAccountExistsContract = {
3267
- method: "POST",
3268
- path: "/_auth/exists",
3269
- body: Type.Object(
3270
- {
3271
- email: Type.Optional(Type.String({
3272
- pattern: EMAIL_PATTERN,
3273
- description: "Email address to check"
3274
- })),
3275
- phone: Type.Optional(Type.String({
3276
- pattern: PHONE_PATTERN,
3277
- description: "Phone number in E.164 format (e.g., +821012345678)"
3278
- }))
3279
- },
3280
- {
3281
- minProperties: 1,
3282
- description: "At least one of email or phone must be provided"
3283
- }
3284
- ),
3285
- response: ApiResponseSchema(
3286
- Type.Object(
3287
- {
3288
- exists: Type.Boolean({ description: "Whether the account exists" }),
3289
- identifier: Type.String({ description: "The identifier that was checked" }),
3290
- identifierType: Type.Union([
3291
- Type.Literal("email"),
3292
- Type.Literal("phone")
3293
- ], { description: "Type of identifier checked" })
3294
- }
3295
- )
3296
- )
3297
- };
3298
- var registerContract = {
3299
- method: "POST",
3300
- path: "/_auth/register",
3301
- body: Type.Object({
3302
- email: Type.Optional(Type.String({
3303
- pattern: EMAIL_PATTERN,
3304
- description: "Email address"
3305
- })),
3306
- phone: Type.Optional(Type.String({
3307
- pattern: PHONE_PATTERN,
3308
- description: "Phone number in E.164 format"
3309
- })),
3310
- verificationToken: Type.String({
3311
- description: "Verification token obtained from /verify-code endpoint"
3312
- }),
3313
- password: Type.String({
3314
- minLength: 8,
3315
- description: "User password (minimum 8 characters)"
3316
- }),
3317
- publicKey: Type.String({
3318
- pattern: BASE64_PATTERN,
3319
- description: "Base64 encoded DER public key (SPKI format)"
3320
- }),
3321
- keyId: Type.String({
3322
- pattern: UUID_PATTERN,
3323
- description: "Client-generated UUID v4 key identifier"
3324
- }),
3325
- fingerprint: Type.String({
3326
- pattern: FINGERPRINT_PATTERN,
3327
- description: "SHA-256 fingerprint of public key (64 hex characters)"
3328
- }),
3329
- algorithm: Type.Union([
3330
- Type.Literal("ES256"),
3331
- Type.Literal("RS256")
3332
- ], {
3333
- description: "Signing algorithm (ES256 recommended, RS256 for compatibility)"
3334
- }),
3335
- keySize: Type.Optional(Type.Number({
3336
- description: "Key size in bytes"
3337
- }))
3338
- }, {
3339
- minProperties: 6,
3340
- // email/phone + verificationToken + password + publicKey + keyId + fingerprint
3341
- description: "Email or phone must be provided with verification token"
3342
- }),
3343
- response: ApiResponseSchema(
3344
- Type.Object({
3345
- userId: Type.String(),
3346
- email: Type.Optional(Type.String()),
3347
- phone: Type.Optional(Type.String())
3348
- })
3349
- )
3350
- };
3351
- var loginContract = {
3352
- method: "POST",
3353
- path: "/_auth/login",
3354
- body: Type.Object({
3355
- email: Type.Optional(Type.String({
3356
- pattern: EMAIL_PATTERN,
3357
- description: "Email address"
3358
- })),
3359
- phone: Type.Optional(Type.String({
3360
- pattern: PHONE_PATTERN,
3361
- description: "Phone number in E.164 format"
3362
- })),
3363
- password: Type.String({
3364
- minLength: 1,
3365
- description: "User password"
3366
- }),
3367
- publicKey: Type.String({
3368
- pattern: BASE64_PATTERN,
3369
- description: "Base64 encoded DER public key (SPKI format)"
3370
- }),
3371
- keyId: Type.String({
3372
- pattern: UUID_PATTERN,
3373
- description: "Client-generated UUID v4 key identifier"
3374
- }),
3375
- fingerprint: Type.String({
3376
- pattern: FINGERPRINT_PATTERN,
3377
- description: "SHA-256 fingerprint of public key (64 hex characters)"
3378
- }),
3379
- oldKeyId: Type.Optional(Type.String({
3380
- pattern: UUID_PATTERN,
3381
- description: "Previous key ID to revoke (server-side cleanup)"
3382
- })),
3383
- algorithm: Type.Union([
3384
- Type.Literal("ES256"),
3385
- Type.Literal("RS256")
3386
- ], {
3387
- description: "Signing algorithm (ES256 recommended, RS256 for compatibility)"
3388
- }),
3389
- keySize: Type.Optional(Type.Number({
3390
- description: "Key size in bytes"
3391
- }))
3392
- }, {
3393
- minProperties: 5,
3394
- // email/phone + password + publicKey + keyId + fingerprint
3395
- description: "Email or phone must be provided along with key data"
3396
- }),
3397
- response: ApiResponseSchema(
3398
- Type.Object({
3399
- userId: Type.String(),
3400
- email: Type.Optional(Type.String()),
3401
- phone: Type.Optional(Type.String()),
3402
- passwordChangeRequired: Type.Boolean({
3403
- description: "Whether user must change password before proceeding"
3404
- })
3405
- })
3406
- )
3407
- };
3408
- var logoutContract = {
3409
- method: "POST",
3410
- path: "/_auth/logout",
3411
- body: Type.Object({}),
3412
- response: ApiResponseSchema(
3413
- Type.Object({
3414
- success: Type.Boolean()
3415
- })
3416
- )
3417
- };
3418
- var rotateKeyContract = {
3419
- method: "POST",
3420
- path: "/_auth/keys/rotate",
3421
- body: Type.Object({
3422
- publicKey: Type.String({
3423
- pattern: BASE64_PATTERN,
3424
- description: "Base64 encoded DER public key (SPKI format)"
3425
- }),
3426
- keyId: Type.String({
3427
- pattern: UUID_PATTERN,
3428
- description: "Client-generated UUID v4 key identifier"
3429
- }),
3430
- fingerprint: Type.String({
3431
- pattern: FINGERPRINT_PATTERN,
3432
- description: "SHA-256 fingerprint of public key (64 hex characters)"
3433
- }),
3434
- algorithm: Type.Union([
3435
- Type.Literal("ES256"),
3436
- Type.Literal("RS256")
3437
- ], {
3438
- description: "Signing algorithm (ES256 recommended, RS256 for compatibility)"
3439
- }),
3440
- keySize: Type.Optional(Type.Number({
3441
- description: "Key size in bytes"
3442
- }))
3443
- }),
3444
- response: ApiResponseSchema(
3445
- Type.Object({
3446
- success: Type.Boolean(),
3447
- keyId: Type.String()
3448
- })
3449
- )
3450
- };
3451
- var changePasswordContract = {
3452
- method: "PUT",
3453
- path: "/_auth/password",
3454
- body: Type.Object({
3455
- currentPassword: Type.String({
3456
- minLength: 1,
3457
- description: "Current password for verification"
3458
- }),
3459
- newPassword: Type.String({
3460
- minLength: 8,
3461
- description: "New password (minimum 8 characters)"
3462
- })
3463
- }),
3464
- response: ApiResponseSchema(
3465
- Type.Object({
3466
- success: Type.Boolean({ description: "Whether password was changed successfully" })
3467
- })
3468
- )
3469
- };
3470
- var getMeContract = {
3471
- method: "GET",
3472
- path: "/_auth/me",
3473
- body: Type.Object({}),
3474
- response: ApiResponseSchema(
3475
- Type.Object({
3476
- userId: Type.String({ description: "User ID" }),
3477
- email: Type.Optional(Type.String({ description: "User email address" })),
3478
- phone: Type.Optional(Type.String({ description: "User phone number" })),
3479
- role: Type.Object({
3480
- id: Type.Number({ description: "Role ID" }),
3481
- name: Type.String({ description: "Role name (e.g., user, admin)" }),
3482
- displayName: Type.String({ description: "Display name for UI" }),
3483
- priority: Type.Number({ description: "Role priority level" })
3484
- }, { description: "User role information" }),
3485
- permissions: Type.Array(
3486
- Type.Object({
3487
- id: Type.Number({ description: "Permission ID" }),
3488
- name: Type.String({ description: "Permission name (e.g., user:delete)" }),
3489
- displayName: Type.String({ description: "Display name for UI" }),
3490
- category: Type.Optional(Type.String({ description: "Permission category" }))
3491
- }),
3492
- { description: "List of permissions granted through role" }
3493
- )
3494
- })
3495
- )
3496
- };
3497
-
3498
- // src/lib/api/auth-me.ts
3499
- var getMe = (options) => client.call(getMeContract, options);
3500
-
3501
- // src/adapters/nextjs/guards/auth-utils.ts
3502
- async function getCurrentUserInfo() {
3503
- try {
3504
- const result = await getMe({ body: {} });
3505
- if (!result.success) {
3506
- return null;
3507
- }
3508
- return result.data;
3509
- } catch (error) {
3510
- console.error("[Auth Utils] Failed to get user info:", error);
3511
- return null;
3512
- }
3513
- }
3514
- async function getUserRole() {
3515
- const userInfo = await getCurrentUserInfo();
3516
- return userInfo?.role.name || null;
3517
- }
3518
- async function getUserPermissions() {
3519
- const userInfo = await getCurrentUserInfo();
3520
- if (!userInfo) {
3521
- return [];
3522
- }
3523
- return userInfo.permissions.map((p) => p.name);
3524
- }
3525
- async function hasAnyRole(requiredRoles) {
3526
- const userInfo = await getCurrentUserInfo();
3527
- if (!userInfo) {
3528
- return false;
3529
- }
3530
- return requiredRoles.includes(userInfo.role.name);
3531
- }
3532
- async function hasAnyPermission(requiredPermissions) {
3533
- const userInfo = await getCurrentUserInfo();
3534
- if (!userInfo) {
3535
- return false;
3536
- }
3537
- const userPermissionNames = userInfo.permissions.map((p) => p.name);
3538
- return requiredPermissions.some((permission) => userPermissionNames.includes(permission));
3539
- }
3540
-
3541
- // src/adapters/nextjs/guards/require-role.tsx
3542
- import { Fragment as Fragment2, jsx as jsx2 } from "react/jsx-runtime";
3543
- async function RequireRole({
3544
- roles,
3545
- children,
3546
- redirectTo = "/unauthorized",
3547
- fallback
3548
- }) {
3549
- const session = await getSession();
3550
- if (!session) {
3551
- if (fallback) {
3552
- return /* @__PURE__ */ jsx2(Fragment2, { children: fallback });
3553
- }
3554
- redirect2("/login");
3555
- }
3556
- const requiredRoles = Array.isArray(roles) ? roles : [roles];
3557
- const hasRole = await hasAnyRole(requiredRoles);
3558
- if (!hasRole) {
3559
- if (fallback) {
3560
- return /* @__PURE__ */ jsx2(Fragment2, { children: fallback });
3561
- }
3562
- redirect2(redirectTo);
3563
- }
3564
- return /* @__PURE__ */ jsx2(Fragment2, { children });
3565
- }
3566
-
3567
- // src/adapters/nextjs/guards/require-permission.tsx
3568
- import { redirect as redirect3 } from "next/navigation";
3569
- import { Fragment as Fragment3, jsx as jsx3 } from "react/jsx-runtime";
3570
- async function RequirePermission({
3571
- permissions,
3572
- children,
3573
- redirectTo = "/unauthorized",
3574
- fallback
3575
- }) {
3576
- const session = await getSession();
3577
- if (!session) {
3578
- if (fallback) {
3579
- return /* @__PURE__ */ jsx3(Fragment3, { children: fallback });
3580
- }
3581
- redirect3("/login");
3582
- }
3583
- const requiredPermissions = Array.isArray(permissions) ? permissions : [permissions];
3584
- const hasPermission = await hasAnyPermission(requiredPermissions);
3585
- if (!hasPermission) {
3586
- if (fallback) {
3587
- return /* @__PURE__ */ jsx3(Fragment3, { children: fallback });
3588
- }
3589
- redirect3(redirectTo);
3590
- }
3591
- return /* @__PURE__ */ jsx3(Fragment3, { children });
3592
- }
3593
-
3594
- // src/adapters/nextjs/session-helpers.ts
3595
- import { cookies } from "next/headers.js";
3596
- async function saveSession(data, maxAge = 60 * 60 * 24 * 7) {
3597
- const token = await sealSession(data, maxAge);
3598
- const cookieStore = await cookies();
3599
- cookieStore.set(COOKIE_NAMES.SESSION, token, {
3600
- httpOnly: true,
3601
- secure: process.env.NODE_ENV === "production",
3602
- sameSite: "strict",
3603
- path: "/",
3604
- maxAge
3605
- });
3606
- }
3607
- async function getSession() {
3608
- const cookieStore = await cookies();
3609
- const sessionCookie = cookieStore.get(COOKIE_NAMES.SESSION);
3610
- if (!sessionCookie) {
3611
- return null;
3612
- }
3613
- try {
3614
- const session = await unsealSession(sessionCookie.value);
3615
- return {
3616
- userId: session.userId
3617
- };
3618
- } catch (error) {
3619
- console.error("[getSession] Failed to unseal session:", error);
3620
- return null;
3621
- }
3622
- }
3623
- async function clearSession() {
3624
- const cookieStore = await cookies();
3625
- cookieStore.delete(COOKIE_NAMES.SESSION);
3626
- cookieStore.delete(COOKIE_NAMES.SESSION_KEY_ID);
3627
- }
3628
- export {
3629
- RequireAuth,
3630
- RequirePermission,
3631
- RequireRole,
3632
- authInterceptors,
3633
- generalAuthInterceptor as authenticationInterceptor,
3634
- clearSession,
3635
- generalAuthInterceptor,
3636
- getSession,
3637
- getUserPermissions,
3638
- getUserRole,
3639
- hasAnyPermission,
3640
- hasAnyRole,
3641
- keyRotationInterceptor,
3642
- loginRegisterInterceptor,
3643
- saveSession
3644
- };
3645
- //# sourceMappingURL=server.js.map