@donotdev/functions 0.1.0 → 0.1.42
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.
- package/LICENSE.md +21 -242
- package/README.md +4 -4
- package/guidelines/FUNCTIONS.md +9 -0
- package/guidelines/VERCEL.md +286 -0
- package/lib/firebase/auth/getCustomClaims.d.ts +0 -0
- package/lib/firebase/auth/getUserAuthStatus.d.ts +0 -0
- package/lib/firebase/auth/index.d.ts +0 -0
- package/lib/firebase/auth/removeCustomClaims.d.ts +0 -0
- package/lib/firebase/auth/setCustomClaims.d.ts +0 -0
- package/lib/firebase/baseFunction.d.ts +0 -0
- package/lib/firebase/billing/cancelSubscription.d.ts +0 -0
- package/lib/firebase/billing/changePlan.d.ts +0 -0
- package/lib/firebase/billing/createCheckoutSession.d.ts +10 -13
- package/lib/firebase/billing/createCustomerPortal.d.ts +0 -0
- package/lib/firebase/billing/healthCheck.d.ts +0 -0
- package/lib/firebase/billing/index.d.ts +0 -0
- package/lib/firebase/billing/refreshSubscriptionStatus.d.ts +0 -0
- package/lib/firebase/billing/webhookHandler.d.ts +0 -0
- package/lib/firebase/config/constants.d.ts +0 -0
- package/lib/firebase/config/index.d.ts +0 -0
- package/lib/firebase/config/secrets.d.ts +0 -0
- package/lib/firebase/crud/aggregate.d.ts +0 -0
- package/lib/firebase/crud/bulk.d.ts +107 -0
- package/lib/firebase/crud/create.d.ts +1 -1
- package/lib/firebase/crud/delete.d.ts +0 -0
- package/lib/firebase/crud/get.d.ts +0 -0
- package/lib/firebase/crud/index.d.ts +1 -0
- package/lib/firebase/crud/list.d.ts +0 -0
- package/lib/firebase/crud/update.d.ts +0 -0
- package/lib/firebase/helpers/githubAccessHelper.d.ts +0 -0
- package/lib/firebase/helpers/githubTeamAccessHelper.d.ts +0 -0
- package/lib/firebase/helpers/index.d.ts +0 -0
- package/lib/firebase/index.d.ts +0 -0
- package/lib/firebase/index.js +3 -3
- package/lib/firebase/index.js.map +4 -4
- package/lib/firebase/oauth/disconnect.d.ts +0 -0
- package/lib/firebase/oauth/exchangeToken.d.ts +0 -0
- package/lib/firebase/oauth/getConnections.d.ts +0 -0
- package/lib/firebase/oauth/githubAccess.d.ts +0 -0
- package/lib/firebase/oauth/index.d.ts +0 -0
- package/lib/firebase/oauth/refreshToken.d.ts +0 -0
- package/lib/firebase/registerCrudFunctions.d.ts +0 -0
- package/lib/firebase/scheduled/checkExpiredSubscriptions.d.ts +0 -0
- package/lib/firebase/scheduled/index.d.ts +0 -0
- package/lib/shared/ai/classifyAIError.d.ts +35 -0
- package/lib/shared/ai/costTracker.d.ts +20 -0
- package/lib/shared/ai/createAIHandler.d.ts +39 -0
- package/lib/shared/ai/createAIRoute.d.ts +20 -0
- package/lib/shared/ai/index.d.ts +6 -0
- package/lib/shared/ai/providers/anthropic.d.ts +12 -0
- package/lib/shared/ai/providers/google.d.ts +10 -0
- package/lib/shared/ai/providers/index.d.ts +23 -0
- package/lib/shared/ai/providers/openai.d.ts +10 -0
- package/lib/shared/ai/resolveModelTier.d.ts +14 -0
- package/lib/shared/ai/utils/parseSSE.d.ts +22 -0
- package/lib/shared/billing/createCheckout.d.ts +8 -2
- package/lib/shared/billing/helpers/index.d.ts +0 -0
- package/lib/shared/billing/helpers/subscriptionManagement.d.ts +0 -0
- package/lib/shared/billing/helpers/updateUserSubscription.d.ts +0 -0
- package/lib/shared/billing/idempotency.d.ts +0 -0
- package/lib/shared/billing/index.d.ts +0 -0
- package/lib/shared/billing/webhookHandler.d.ts +0 -0
- package/lib/shared/crud/bulkCore.d.ts +211 -0
- package/lib/shared/crud/index.d.ts +13 -0
- package/lib/shared/email/createEmailRoute.d.ts +30 -0
- package/lib/shared/email/index.d.ts +3 -0
- package/lib/shared/email/provider.d.ts +30 -0
- package/lib/shared/email/resendProvider.d.ts +22 -0
- package/lib/shared/errorHandling.d.ts +0 -0
- package/lib/shared/firebase.d.ts +0 -0
- package/lib/shared/github.d.ts +5 -0
- package/lib/shared/index.d.ts +3 -0
- package/lib/shared/index.js +4 -3
- package/lib/shared/index.js.map +4 -4
- package/lib/shared/logger.d.ts +2 -0
- package/lib/shared/metadata.d.ts +6 -6
- package/lib/shared/oauth/exchangeToken.d.ts +1 -0
- package/lib/shared/oauth/grantAccess.d.ts +1 -0
- package/lib/shared/oauth/index.d.ts +0 -0
- package/lib/shared/schema.d.ts +0 -0
- package/lib/shared/utils/detectFirestore.d.ts +0 -0
- package/lib/shared/utils/external/date.d.ts +0 -0
- package/lib/shared/utils/external/index.d.ts +0 -0
- package/lib/shared/utils/external/references.d.ts +0 -0
- package/lib/shared/utils/external/subscription.d.ts +0 -0
- package/lib/shared/utils/firebaseHelpers.d.ts +0 -0
- package/lib/shared/utils/functionWrapper.d.ts +0 -0
- package/lib/shared/utils/index.d.ts +0 -0
- package/lib/shared/utils/internal/auth.d.ts +0 -0
- package/lib/shared/utils/internal/firebase.d.ts +0 -0
- package/lib/shared/utils/internal/idempotency.d.ts +1 -0
- package/lib/shared/utils/internal/index.d.ts +0 -0
- package/lib/shared/utils/internal/monitoring.d.ts +0 -0
- package/lib/shared/utils/internal/rateLimiter.d.ts +0 -0
- package/lib/shared/utils/internal/validation.d.ts +0 -0
- package/lib/shared/utils/schemaValidation.d.ts +0 -0
- package/lib/shared/utils/validation.d.ts +0 -0
- package/lib/shared/utils/vercelHelpers.d.ts +0 -0
- package/lib/shared/utils.d.ts +0 -0
- package/lib/shared/validation.d.ts +0 -0
- package/lib/supabase/ai/createAIFunction.d.ts +30 -0
- package/lib/supabase/auth/deleteAccount.d.ts +0 -0
- package/lib/supabase/auth/getCustomClaims.d.ts +0 -0
- package/lib/supabase/auth/getUserAuthStatus.d.ts +0 -0
- package/lib/supabase/auth/removeCustomClaims.d.ts +1 -1
- package/lib/supabase/auth/setCustomClaims.d.ts +12 -4
- package/lib/supabase/baseFunction.d.ts +0 -0
- package/lib/supabase/billing/cancelSubscription.d.ts +0 -0
- package/lib/supabase/billing/changePlan.d.ts +1 -1
- package/lib/supabase/billing/createCheckoutSession.d.ts +0 -0
- package/lib/supabase/billing/createCustomerPortal.d.ts +0 -0
- package/lib/supabase/billing/refreshSubscriptionStatus.d.ts +0 -0
- package/lib/supabase/crud/aggregate.d.ts +1 -0
- package/lib/supabase/crud/bulk.d.ts +63 -0
- package/lib/supabase/crud/create.d.ts +2 -1
- package/lib/supabase/crud/delete.d.ts +1 -0
- package/lib/supabase/crud/get.d.ts +1 -0
- package/lib/supabase/crud/index.d.ts +2 -0
- package/lib/supabase/crud/list.d.ts +1 -0
- package/lib/supabase/crud/update.d.ts +1 -0
- package/lib/supabase/edgeFunction.d.ts +56 -0
- package/lib/supabase/email/createEmailFunction.d.ts +31 -0
- package/lib/supabase/helpers/authProvider.d.ts +0 -0
- package/lib/supabase/index.d.ts +8 -0
- package/lib/supabase/index.js +3 -2
- package/lib/supabase/index.js.map +4 -4
- package/lib/supabase/oauth/disconnect.d.ts +0 -0
- package/lib/supabase/oauth/exchangeToken.d.ts +0 -0
- package/lib/supabase/oauth/getConnections.d.ts +0 -0
- package/lib/supabase/oauth/index.d.ts +0 -0
- package/lib/supabase/oauth/refreshToken.d.ts +0 -0
- package/lib/supabase/registerCrudFunctions.d.ts +0 -0
- package/lib/supabase/utils/idempotency.d.ts +0 -0
- package/lib/supabase/utils/monitoring.d.ts +0 -0
- package/lib/supabase/utils/rateLimiter.d.ts +0 -0
- package/lib/vercel/api/ai/chat.d.ts +29 -0
- package/lib/vercel/api/ai/index.d.ts +1 -0
- package/lib/vercel/api/auth/get-custom-claims.d.ts +0 -0
- package/lib/vercel/api/auth/get-user-auth-status.d.ts +0 -0
- package/lib/vercel/api/auth/index.d.ts +0 -0
- package/lib/vercel/api/auth/remove-custom-claims.d.ts +0 -0
- package/lib/vercel/api/auth/set-custom-claims.d.ts +0 -0
- package/lib/vercel/api/billing/cancel.d.ts +0 -0
- package/lib/vercel/api/billing/change-plan.d.ts +0 -0
- package/lib/vercel/api/billing/create-checkout-session.d.ts +0 -0
- package/lib/vercel/api/billing/customer-portal.d.ts +0 -0
- package/lib/vercel/api/billing/index.d.ts +0 -0
- package/lib/vercel/api/billing/refresh-subscription-status.d.ts +0 -0
- package/lib/vercel/api/billing/webhook-handler.d.ts +0 -0
- package/lib/vercel/api/config/constants.d.ts +0 -0
- package/lib/vercel/api/config/firebase-admin.d.ts +0 -0
- package/lib/vercel/api/config/index.d.ts +0 -0
- package/lib/vercel/api/crud/bulk.d.ts +31 -0
- package/lib/vercel/api/crud/create.d.ts +0 -0
- package/lib/vercel/api/crud/delete.d.ts +0 -0
- package/lib/vercel/api/crud/get.d.ts +0 -0
- package/lib/vercel/api/crud/index.d.ts +1 -0
- package/lib/vercel/api/crud/list.d.ts +0 -0
- package/lib/vercel/api/crud/update.d.ts +0 -0
- package/lib/vercel/api/index.d.ts +1 -0
- package/lib/vercel/api/index.js +3 -2
- package/lib/vercel/api/index.js.map +4 -4
- package/lib/vercel/api/oauth/check-github-access.d.ts +0 -0
- package/lib/vercel/api/oauth/exchange-token.d.ts +0 -0
- package/lib/vercel/api/oauth/grant-github-access.d.ts +0 -0
- package/lib/vercel/api/oauth/index.d.ts +0 -0
- package/lib/vercel/api/oauth/revoke-github-access.d.ts +0 -0
- package/lib/vercel/api/utils/cors.d.ts +0 -0
- package/lib/vercel/baseFunction.d.ts +0 -0
- package/package.json +40 -7
- package/src/firebase/auth/getCustomClaims.ts +0 -0
- package/src/firebase/auth/getUserAuthStatus.ts +0 -0
- package/src/firebase/auth/index.ts +0 -0
- package/src/firebase/auth/removeCustomClaims.ts +0 -0
- package/src/firebase/auth/setCustomClaims.ts +0 -0
- package/src/firebase/baseFunction.ts +0 -0
- package/src/firebase/billing/cancelSubscription.ts +0 -0
- package/src/firebase/billing/changePlan.ts +0 -0
- package/src/firebase/billing/createCheckoutSession.ts +82 -186
- package/src/firebase/billing/createCustomerPortal.ts +0 -0
- package/src/firebase/billing/healthCheck.ts +0 -0
- package/src/firebase/billing/index.d.ts +0 -0
- package/src/firebase/billing/index.ts +0 -0
- package/src/firebase/billing/refreshSubscriptionStatus.ts +0 -0
- package/src/firebase/billing/webhookHandler.ts +0 -0
- package/src/firebase/config/constants.ts +0 -0
- package/src/firebase/config/index.ts +0 -0
- package/src/firebase/config/secrets.ts +0 -0
- package/src/firebase/crud/__tests__/bulk.test.ts +322 -0
- package/src/firebase/crud/aggregate.ts +0 -0
- package/src/firebase/crud/bulk.ts +272 -0
- package/src/firebase/crud/create.ts +20 -33
- package/src/firebase/crud/delete.ts +0 -0
- package/src/firebase/crud/get.ts +0 -0
- package/src/firebase/crud/index.ts +1 -0
- package/src/firebase/crud/list.ts +0 -0
- package/src/firebase/crud/update.ts +0 -0
- package/src/firebase/helpers/githubAccessHelper.ts +0 -0
- package/src/firebase/helpers/githubTeamAccessHelper.ts +0 -0
- package/src/firebase/helpers/index.ts +0 -0
- package/src/firebase/index.d.ts +0 -0
- package/src/firebase/index.ts +0 -0
- package/src/firebase/oauth/disconnect.ts +0 -0
- package/src/firebase/oauth/exchangeToken.ts +4 -4
- package/src/firebase/oauth/getConnections.ts +0 -0
- package/src/firebase/oauth/githubAccess.ts +0 -0
- package/src/firebase/oauth/index.ts +0 -0
- package/src/firebase/oauth/refreshToken.ts +4 -4
- package/src/firebase/registerCrudFunctions.ts +13 -0
- package/src/firebase/scheduled/checkExpiredSubscriptions.ts +0 -0
- package/src/firebase/scheduled/index.ts +0 -0
- package/src/shared/__tests__/auth.test.ts +0 -0
- package/src/shared/__tests__/bulkCore.test.ts +487 -0
- package/src/shared/__tests__/errorHandling.test.ts +0 -0
- package/src/shared/__tests__/firebase.test.ts +9 -3
- package/src/shared/__tests__/idempotency.test.ts +0 -0
- package/src/shared/__tests__/internalValidation.test.ts +9 -3
- package/src/shared/__tests__/metadata.test.ts +10 -10
- package/src/shared/__tests__/rateLimiter.test.ts +0 -0
- package/src/shared/__tests__/schema.test.ts +0 -0
- package/src/shared/__tests__/schemaValidation.test.ts +0 -0
- package/src/shared/__tests__/subscription.test.ts +0 -0
- package/src/shared/__tests__/utils.test.ts +10 -4
- package/src/shared/__tests__/validation-env.test.ts +9 -3
- package/src/shared/__tests__/validation.test.ts +0 -0
- package/src/shared/ai/__tests__/costTracker.test.ts +133 -0
- package/src/shared/ai/classifyAIError.ts +178 -0
- package/src/shared/ai/costTracker.ts +51 -0
- package/src/shared/ai/createAIRoute.ts +400 -0
- package/src/shared/ai/index.ts +8 -0
- package/src/shared/ai/resolveModelTier.ts +61 -0
- package/src/shared/billing/__tests__/createCheckout.test.ts +0 -0
- package/src/shared/billing/__tests__/webhookHandler.test.ts +0 -0
- package/src/shared/billing/createCheckout.ts +168 -8
- package/src/shared/billing/helpers/index.ts +0 -0
- package/src/shared/billing/helpers/subscriptionManagement.ts +9 -0
- package/src/shared/billing/helpers/updateUserSubscription.ts +0 -0
- package/src/shared/billing/idempotency.ts +5 -0
- package/src/shared/billing/index.ts +0 -0
- package/src/shared/billing/webhookHandler.ts +0 -0
- package/src/shared/crud/bulkCore.ts +483 -0
- package/src/shared/crud/index.ts +23 -0
- package/src/shared/email/createEmailRoute.ts +81 -0
- package/src/shared/email/index.ts +5 -0
- package/src/shared/email/provider.ts +31 -0
- package/src/shared/email/resendProvider.ts +56 -0
- package/src/shared/errorHandling.ts +10 -4
- package/src/shared/firebase.ts +0 -0
- package/src/shared/github.ts +38 -0
- package/src/shared/index.d.ts +9 -0
- package/src/shared/index.ts +3 -0
- package/src/shared/logger.ts +2 -0
- package/src/shared/metadata.ts +6 -6
- package/src/shared/oauth/__tests__/exchangeToken.test.ts +0 -0
- package/src/shared/oauth/__tests__/grantAccess.test.ts +0 -0
- package/src/shared/oauth/exchangeToken.ts +1 -0
- package/src/shared/oauth/grantAccess.ts +1 -0
- package/src/shared/oauth/index.ts +0 -0
- package/src/shared/schema.ts +0 -0
- package/src/shared/utils/__tests__/functionWrapper.test.ts +0 -0
- package/src/shared/utils/detectFirestore.ts +0 -0
- package/src/shared/utils/external/date.ts +0 -0
- package/src/shared/utils/external/index.ts +0 -0
- package/src/shared/utils/external/references.ts +0 -0
- package/src/shared/utils/external/subscription.ts +0 -0
- package/src/shared/utils/firebaseHelpers.ts +0 -0
- package/src/shared/utils/functionWrapper.ts +0 -0
- package/src/shared/utils/index.ts +0 -0
- package/src/shared/utils/internal/auth.ts +0 -0
- package/src/shared/utils/internal/firebase.ts +0 -0
- package/src/shared/utils/internal/idempotency.ts +1 -0
- package/src/shared/utils/internal/index.ts +0 -0
- package/src/shared/utils/internal/monitoring.ts +0 -0
- package/src/shared/utils/internal/rateLimiter.ts +6 -3
- package/src/shared/utils/internal/validation.ts +0 -0
- package/src/shared/utils/schemaValidation.ts +0 -0
- package/src/shared/utils/validation.ts +0 -0
- package/src/shared/utils/vercelHelpers.ts +0 -0
- package/src/shared/utils.ts +0 -0
- package/src/shared/validation.ts +1 -1
- package/src/supabase/__tests__/bulk.test.ts +330 -0
- package/src/supabase/ai/createAIFunction.ts +76 -0
- package/src/supabase/auth/deleteAccount.ts +0 -0
- package/src/supabase/auth/getCustomClaims.ts +0 -0
- package/src/supabase/auth/getUserAuthStatus.ts +0 -0
- package/src/supabase/auth/removeCustomClaims.ts +38 -2
- package/src/supabase/auth/setCustomClaims.ts +64 -5
- package/src/supabase/baseFunction.ts +26 -2
- package/src/supabase/billing/cancelSubscription.ts +0 -0
- package/src/supabase/billing/changePlan.ts +6 -1
- package/src/supabase/billing/createCheckoutSession.ts +16 -2
- package/src/supabase/billing/createCustomerPortal.ts +0 -0
- package/src/supabase/billing/refreshSubscriptionStatus.ts +0 -0
- package/src/supabase/crud/aggregate.ts +1 -0
- package/src/supabase/crud/bulk.ts +244 -0
- package/src/supabase/crud/create.ts +16 -14
- package/src/supabase/crud/delete.ts +1 -0
- package/src/supabase/crud/get.ts +1 -0
- package/src/supabase/crud/index.ts +2 -0
- package/src/supabase/crud/list.ts +1 -0
- package/src/supabase/crud/update.ts +1 -0
- package/src/supabase/edgeFunction.ts +196 -0
- package/src/supabase/email/createEmailFunction.ts +72 -0
- package/src/supabase/helpers/authProvider.ts +0 -0
- package/src/supabase/index.ts +21 -0
- package/src/supabase/oauth/disconnect.ts +1 -2
- package/src/supabase/oauth/exchangeToken.ts +39 -10
- package/src/supabase/oauth/getConnections.ts +1 -4
- package/src/supabase/oauth/index.ts +0 -0
- package/src/supabase/oauth/refreshToken.ts +6 -12
- package/src/supabase/registerCrudFunctions.ts +20 -20
- package/src/supabase/utils/idempotency.ts +6 -2
- package/src/supabase/utils/monitoring.ts +0 -0
- package/src/supabase/utils/rateLimiter.ts +0 -0
- package/src/vercel/__tests__/bulk.test.ts +301 -0
- package/src/vercel/api/ai/chat.ts +77 -0
- package/src/vercel/api/ai/index.ts +3 -0
- package/src/vercel/api/auth/get-custom-claims.ts +0 -0
- package/src/vercel/api/auth/get-user-auth-status.ts +0 -0
- package/src/vercel/api/auth/index.ts +0 -0
- package/src/vercel/api/auth/remove-custom-claims.ts +0 -0
- package/src/vercel/api/auth/set-custom-claims.ts +0 -0
- package/src/vercel/api/billing/cancel.ts +0 -0
- package/src/vercel/api/billing/change-plan.ts +0 -0
- package/src/vercel/api/billing/create-checkout-session.ts +31 -4
- package/src/vercel/api/billing/customer-portal.ts +0 -0
- package/src/vercel/api/billing/index.ts +0 -0
- package/src/vercel/api/billing/refresh-subscription-status.ts +0 -0
- package/src/vercel/api/billing/webhook-handler.ts +8 -1
- package/src/vercel/api/config/constants.ts +0 -0
- package/src/vercel/api/config/firebase-admin.ts +0 -0
- package/src/vercel/api/config/index.ts +0 -0
- package/src/vercel/api/crud/bulk.ts +216 -0
- package/src/vercel/api/crud/create.ts +10 -9
- package/src/vercel/api/crud/delete.ts +0 -0
- package/src/vercel/api/crud/get.ts +0 -0
- package/src/vercel/api/crud/index.ts +1 -0
- package/src/vercel/api/crud/list.ts +0 -0
- package/src/vercel/api/crud/update.ts +0 -0
- package/src/vercel/api/index.d.ts +0 -0
- package/src/vercel/api/index.ts +1 -0
- package/src/vercel/api/oauth/check-github-access.ts +0 -0
- package/src/vercel/api/oauth/exchange-token.ts +27 -1
- package/src/vercel/api/oauth/grant-github-access.ts +0 -0
- package/src/vercel/api/oauth/index.ts +0 -0
- package/src/vercel/api/oauth/revoke-github-access.ts +0 -0
- package/src/vercel/api/utils/cors.ts +8 -0
- package/src/vercel/baseFunction.ts +0 -0
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/src/firebase/index.d.ts
CHANGED
|
File without changes
|
package/src/firebase/index.ts
CHANGED
|
File without changes
|
|
File without changes
|
|
@@ -103,10 +103,10 @@ export const exchangeToken = onCall<ExchangeTokenRequest>(async (request) => {
|
|
|
103
103
|
);
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
// Get client
|
|
107
|
-
const
|
|
108
|
-
const
|
|
109
|
-
|
|
106
|
+
// Get client credentials: {PROVIDER}_CLIENT_ID, {PROVIDER}_CLIENT_SECRET
|
|
107
|
+
const upper = provider.toUpperCase();
|
|
108
|
+
const clientId = process.env[`${upper}_CLIENT_ID`];
|
|
109
|
+
const clientSecret = process.env[`${upper}_CLIENT_SECRET`];
|
|
110
110
|
|
|
111
111
|
if (!clientId || !clientSecret) {
|
|
112
112
|
throw new HttpsError(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -49,10 +49,10 @@ export const refreshToken = onCall<OAuthRefreshRequest>(async (request) => {
|
|
|
49
49
|
);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
// Get client credentials
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
|
|
52
|
+
// Get client credentials: {PROVIDER}_CLIENT_ID, {PROVIDER}_CLIENT_SECRET
|
|
53
|
+
const upper = provider.toUpperCase();
|
|
54
|
+
const clientId = process.env[`${upper}_CLIENT_ID`];
|
|
55
|
+
const clientSecret = process.env[`${upper}_CLIENT_SECRET`];
|
|
56
56
|
|
|
57
57
|
if (!clientId || !clientSecret) {
|
|
58
58
|
throw new HttpsError(
|
|
@@ -13,6 +13,7 @@ import { createSchemas, getListCardFieldNames } from '@donotdev/core/server';
|
|
|
13
13
|
import type { Entity } from '@donotdev/core/server';
|
|
14
14
|
|
|
15
15
|
import {
|
|
16
|
+
bulkEntity,
|
|
16
17
|
createEntity,
|
|
17
18
|
getEntity,
|
|
18
19
|
updateEntity,
|
|
@@ -65,6 +66,7 @@ export function createCrudFunctions(
|
|
|
65
66
|
functions[`${prefix}create_${col}`] = createEntity(
|
|
66
67
|
col,
|
|
67
68
|
schemas.create,
|
|
69
|
+
schemas.draft,
|
|
68
70
|
access.create
|
|
69
71
|
);
|
|
70
72
|
functions[`${prefix}get_${col}`] = getEntity(
|
|
@@ -101,6 +103,17 @@ export function createCrudFunctions(
|
|
|
101
103
|
access.update
|
|
102
104
|
);
|
|
103
105
|
functions[`${prefix}delete_${col}`] = deleteEntity(col, access.delete);
|
|
106
|
+
functions[`${prefix}bulk_${col}`] = bulkEntity(
|
|
107
|
+
col,
|
|
108
|
+
schemas.create,
|
|
109
|
+
schemas.draft,
|
|
110
|
+
schemas.update,
|
|
111
|
+
{
|
|
112
|
+
create: access.create,
|
|
113
|
+
update: access.update,
|
|
114
|
+
delete: access.delete,
|
|
115
|
+
}
|
|
116
|
+
);
|
|
104
117
|
}
|
|
105
118
|
|
|
106
119
|
return functions;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,487 @@
|
|
|
1
|
+
// packages/functions/src/shared/__tests__/bulkCore.test.ts
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Unit tests for {@link executeBulk}.
|
|
5
|
+
* @description Exercises the shared orchestration contract directly with a
|
|
6
|
+
* mock `transact` callback — empty short-circuit, collision rejection,
|
|
7
|
+
* per-bucket ACL, per-row validation (inserts + updates), single-invocation
|
|
8
|
+
* transact with prepared payload, response-schema validation, and audit
|
|
9
|
+
* firing once with counts.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
13
|
+
import * as v from 'valibot';
|
|
14
|
+
|
|
15
|
+
import { executeBulk } from '../crud/bulkCore.js';
|
|
16
|
+
import { BulkCollisionError } from '@donotdev/core/server';
|
|
17
|
+
import { DoNotDevError } from '@donotdev/core/server';
|
|
18
|
+
import { DEFAULT_STATUS_VALUE } from '@donotdev/core/server';
|
|
19
|
+
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// Fixtures
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
|
|
24
|
+
const createSchema = v.object({ name: v.pipe(v.string(), v.minLength(1)) });
|
|
25
|
+
const updateSchema = v.object({ name: v.optional(v.string()) });
|
|
26
|
+
|
|
27
|
+
const ACCESS = {
|
|
28
|
+
create: 'user' as const,
|
|
29
|
+
read: 'user' as const,
|
|
30
|
+
update: 'user' as const,
|
|
31
|
+
delete: 'user' as const,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** Default response-shape returned by the mock transact. */
|
|
35
|
+
function okResponse(prepared: {
|
|
36
|
+
inserts: Array<{ id: string; row: Record<string, unknown> }>;
|
|
37
|
+
updates: Array<{ id: string; patch: Record<string, unknown> }>;
|
|
38
|
+
deletes: string[];
|
|
39
|
+
}) {
|
|
40
|
+
return {
|
|
41
|
+
insertedIds: prepared.inserts.map((i, idx) => i.id || `auto-${idx + 1}`),
|
|
42
|
+
updatedIds: prepared.updates.map((u) => u.id),
|
|
43
|
+
deletedIds: [...prepared.deletes],
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
// Tests
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
|
|
51
|
+
describe('executeBulk (shared CRUD core)', () => {
|
|
52
|
+
it('empty bulk short-circuits: no transact, no audit', async () => {
|
|
53
|
+
const transact = vi.fn();
|
|
54
|
+
const audit = vi.fn();
|
|
55
|
+
|
|
56
|
+
const result = await executeBulk({
|
|
57
|
+
collection: 'events',
|
|
58
|
+
ops: {},
|
|
59
|
+
createSchema,
|
|
60
|
+
updateSchema,
|
|
61
|
+
access: ACCESS,
|
|
62
|
+
uid: 'u1',
|
|
63
|
+
userRole: 'user',
|
|
64
|
+
transact,
|
|
65
|
+
audit,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
expect(result).toEqual({
|
|
69
|
+
insertedIds: [],
|
|
70
|
+
updatedIds: [],
|
|
71
|
+
deletedIds: [],
|
|
72
|
+
});
|
|
73
|
+
expect(transact).not.toHaveBeenCalled();
|
|
74
|
+
expect(audit).not.toHaveBeenCalled();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('empty arrays also short-circuit', async () => {
|
|
78
|
+
const transact = vi.fn();
|
|
79
|
+
const audit = vi.fn();
|
|
80
|
+
|
|
81
|
+
const result = await executeBulk({
|
|
82
|
+
collection: 'events',
|
|
83
|
+
ops: { inserts: [], updates: [], deletes: [] },
|
|
84
|
+
createSchema,
|
|
85
|
+
updateSchema,
|
|
86
|
+
access: ACCESS,
|
|
87
|
+
uid: 'u1',
|
|
88
|
+
userRole: 'user',
|
|
89
|
+
transact,
|
|
90
|
+
audit,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
expect(result).toEqual({
|
|
94
|
+
insertedIds: [],
|
|
95
|
+
updatedIds: [],
|
|
96
|
+
deletedIds: [],
|
|
97
|
+
});
|
|
98
|
+
expect(transact).not.toHaveBeenCalled();
|
|
99
|
+
expect(audit).not.toHaveBeenCalled();
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('rejects with BulkCollisionError on updates/deletes collision, no transact', async () => {
|
|
103
|
+
const transact = vi.fn();
|
|
104
|
+
const audit = vi.fn();
|
|
105
|
+
|
|
106
|
+
await expect(
|
|
107
|
+
executeBulk({
|
|
108
|
+
collection: 'events',
|
|
109
|
+
ops: {
|
|
110
|
+
updates: [{ id: 'a', patch: { name: 'x' } }],
|
|
111
|
+
deletes: ['a'],
|
|
112
|
+
},
|
|
113
|
+
createSchema,
|
|
114
|
+
updateSchema,
|
|
115
|
+
access: ACCESS,
|
|
116
|
+
uid: 'u1',
|
|
117
|
+
userRole: 'user',
|
|
118
|
+
transact,
|
|
119
|
+
audit,
|
|
120
|
+
})
|
|
121
|
+
).rejects.toBeInstanceOf(BulkCollisionError);
|
|
122
|
+
|
|
123
|
+
expect(transact).not.toHaveBeenCalled();
|
|
124
|
+
expect(audit).not.toHaveBeenCalled();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('rejects with BulkCollisionError on inserts/updates id collision', async () => {
|
|
128
|
+
const transact = vi.fn();
|
|
129
|
+
|
|
130
|
+
await expect(
|
|
131
|
+
executeBulk({
|
|
132
|
+
collection: 'events',
|
|
133
|
+
ops: {
|
|
134
|
+
inserts: [{ id: 'shared', name: 'new' }],
|
|
135
|
+
updates: [{ id: 'shared', patch: { name: 'x' } }],
|
|
136
|
+
},
|
|
137
|
+
createSchema,
|
|
138
|
+
updateSchema,
|
|
139
|
+
access: ACCESS,
|
|
140
|
+
uid: 'u1',
|
|
141
|
+
userRole: 'user',
|
|
142
|
+
transact,
|
|
143
|
+
})
|
|
144
|
+
).rejects.toMatchObject({
|
|
145
|
+
where: 'inserts-updates',
|
|
146
|
+
collidingIds: ['shared'],
|
|
147
|
+
});
|
|
148
|
+
expect(transact).not.toHaveBeenCalled();
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('per-bucket ACL: populated deletes bucket rejects when role insufficient', async () => {
|
|
152
|
+
const transact = vi.fn();
|
|
153
|
+
|
|
154
|
+
await expect(
|
|
155
|
+
executeBulk({
|
|
156
|
+
collection: 'events',
|
|
157
|
+
ops: { deletes: ['a', 'b'] },
|
|
158
|
+
createSchema,
|
|
159
|
+
updateSchema,
|
|
160
|
+
access: { ...ACCESS, delete: 'admin' },
|
|
161
|
+
uid: 'u1',
|
|
162
|
+
userRole: 'user',
|
|
163
|
+
transact,
|
|
164
|
+
})
|
|
165
|
+
).rejects.toMatchObject({
|
|
166
|
+
code: 'permission-denied',
|
|
167
|
+
message: expect.stringContaining('admin'),
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
expect(transact).not.toHaveBeenCalled();
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('per-bucket ACL: populated bucket without configured role is a config error', async () => {
|
|
174
|
+
const transact = vi.fn();
|
|
175
|
+
|
|
176
|
+
await expect(
|
|
177
|
+
executeBulk({
|
|
178
|
+
collection: 'events',
|
|
179
|
+
ops: { inserts: [{ name: 'A' }] },
|
|
180
|
+
createSchema,
|
|
181
|
+
updateSchema,
|
|
182
|
+
access: { read: 'user' }, // no create role configured
|
|
183
|
+
uid: 'u1',
|
|
184
|
+
userRole: 'user',
|
|
185
|
+
transact,
|
|
186
|
+
})
|
|
187
|
+
).rejects.toMatchObject({
|
|
188
|
+
code: 'permission-denied',
|
|
189
|
+
message: expect.stringContaining('no create role is configured'),
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
expect(transact).not.toHaveBeenCalled();
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('empty-bucket ACL: unpopulated buckets do not block execution', async () => {
|
|
196
|
+
// Only the update bucket carries work; a deletes-without-role config does
|
|
197
|
+
// NOT fail because the deletes bucket is empty.
|
|
198
|
+
const transact = vi.fn(okResponse);
|
|
199
|
+
|
|
200
|
+
const result = await executeBulk({
|
|
201
|
+
collection: 'events',
|
|
202
|
+
ops: { updates: [{ id: 'u1', patch: { name: 'x' } }] },
|
|
203
|
+
createSchema,
|
|
204
|
+
updateSchema,
|
|
205
|
+
access: { update: 'user' }, // no create/delete roles configured — fine
|
|
206
|
+
uid: 'u1',
|
|
207
|
+
userRole: 'user',
|
|
208
|
+
transact,
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
expect(transact).toHaveBeenCalledTimes(1);
|
|
212
|
+
expect(result.updatedIds).toEqual(['u1']);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('validation failure on insert: prefixed with inserts[i], no transact', async () => {
|
|
216
|
+
const transact = vi.fn();
|
|
217
|
+
|
|
218
|
+
await expect(
|
|
219
|
+
executeBulk({
|
|
220
|
+
collection: 'events',
|
|
221
|
+
ops: {
|
|
222
|
+
inserts: [{ name: 'Alice' }, { name: '' }], // index 1 invalid
|
|
223
|
+
},
|
|
224
|
+
createSchema,
|
|
225
|
+
updateSchema,
|
|
226
|
+
access: ACCESS,
|
|
227
|
+
uid: 'u1',
|
|
228
|
+
userRole: 'user',
|
|
229
|
+
transact,
|
|
230
|
+
})
|
|
231
|
+
).rejects.toMatchObject({
|
|
232
|
+
code: 'invalid-argument',
|
|
233
|
+
message: expect.stringContaining('inserts[1]'),
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
expect(transact).not.toHaveBeenCalled();
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it('validation failure on update patch: prefixed with updates[i], no transact', async () => {
|
|
240
|
+
const transact = vi.fn();
|
|
241
|
+
|
|
242
|
+
await expect(
|
|
243
|
+
executeBulk({
|
|
244
|
+
collection: 'events',
|
|
245
|
+
ops: {
|
|
246
|
+
updates: [{ id: 'u1', patch: { name: 123 as any } }],
|
|
247
|
+
},
|
|
248
|
+
createSchema,
|
|
249
|
+
updateSchema,
|
|
250
|
+
access: ACCESS,
|
|
251
|
+
uid: 'u1',
|
|
252
|
+
userRole: 'user',
|
|
253
|
+
transact,
|
|
254
|
+
})
|
|
255
|
+
).rejects.toMatchObject({
|
|
256
|
+
code: 'invalid-argument',
|
|
257
|
+
message: expect.stringContaining('updates[0]'),
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
expect(transact).not.toHaveBeenCalled();
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it('wire-schema failure throws invalid-argument without calling transact', async () => {
|
|
264
|
+
const transact = vi.fn();
|
|
265
|
+
|
|
266
|
+
await expect(
|
|
267
|
+
executeBulk({
|
|
268
|
+
collection: 'events',
|
|
269
|
+
// Malformed: updates[0] missing `id`.
|
|
270
|
+
ops: { updates: [{ patch: { name: 'x' } } as any] },
|
|
271
|
+
createSchema,
|
|
272
|
+
updateSchema,
|
|
273
|
+
access: ACCESS,
|
|
274
|
+
uid: 'u1',
|
|
275
|
+
userRole: 'user',
|
|
276
|
+
transact,
|
|
277
|
+
})
|
|
278
|
+
).rejects.toMatchObject({
|
|
279
|
+
code: 'invalid-argument',
|
|
280
|
+
message: expect.stringContaining('Bulk payload validation failed'),
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
expect(transact).not.toHaveBeenCalled();
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('transact called exactly once with prepared payload (minted ids + stamped metadata)', async () => {
|
|
287
|
+
let mintCounter = 0;
|
|
288
|
+
const transact = vi.fn(okResponse);
|
|
289
|
+
const audit = vi.fn();
|
|
290
|
+
|
|
291
|
+
const result = await executeBulk({
|
|
292
|
+
collection: 'events',
|
|
293
|
+
ops: {
|
|
294
|
+
inserts: [{ name: 'Alice' }, { name: 'Bob' }],
|
|
295
|
+
updates: [{ id: 'u1', patch: { name: 'Renamed' } }],
|
|
296
|
+
deletes: ['d1'],
|
|
297
|
+
},
|
|
298
|
+
createSchema,
|
|
299
|
+
updateSchema,
|
|
300
|
+
access: ACCESS,
|
|
301
|
+
uid: 'user-1',
|
|
302
|
+
userRole: 'user',
|
|
303
|
+
mintInsertId: () => `mint-${++mintCounter}`,
|
|
304
|
+
stampInsertMetadata: (row, uid) => ({ ...row, _uid: uid, _kind: 'ins' }),
|
|
305
|
+
stampUpdateMetadata: (patch, uid) => ({
|
|
306
|
+
...patch,
|
|
307
|
+
_uid: uid,
|
|
308
|
+
_kind: 'upd',
|
|
309
|
+
}),
|
|
310
|
+
transact,
|
|
311
|
+
audit,
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
expect(transact).toHaveBeenCalledTimes(1);
|
|
315
|
+
const [prepared] = transact.mock.calls[0];
|
|
316
|
+
expect(prepared.inserts).toEqual([
|
|
317
|
+
{
|
|
318
|
+
id: 'mint-1',
|
|
319
|
+
row: {
|
|
320
|
+
name: 'Alice',
|
|
321
|
+
status: DEFAULT_STATUS_VALUE,
|
|
322
|
+
_uid: 'user-1',
|
|
323
|
+
_kind: 'ins',
|
|
324
|
+
},
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
id: 'mint-2',
|
|
328
|
+
row: {
|
|
329
|
+
name: 'Bob',
|
|
330
|
+
status: DEFAULT_STATUS_VALUE,
|
|
331
|
+
_uid: 'user-1',
|
|
332
|
+
_kind: 'ins',
|
|
333
|
+
},
|
|
334
|
+
},
|
|
335
|
+
]);
|
|
336
|
+
expect(prepared.updates).toEqual([
|
|
337
|
+
{
|
|
338
|
+
id: 'u1',
|
|
339
|
+
patch: { name: 'Renamed', _uid: 'user-1', _kind: 'upd' },
|
|
340
|
+
},
|
|
341
|
+
]);
|
|
342
|
+
expect(prepared.deletes).toEqual(['d1']);
|
|
343
|
+
|
|
344
|
+
// Response echoes input order.
|
|
345
|
+
expect(result.insertedIds).toEqual(['mint-1', 'mint-2']);
|
|
346
|
+
expect(result.updatedIds).toEqual(['u1']);
|
|
347
|
+
expect(result.deletedIds).toEqual(['d1']);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it('transact runs without mintInsertId: id is empty string, target mints its own', async () => {
|
|
351
|
+
const transact = vi.fn(() =>
|
|
352
|
+
// Target mints server-side and returns the ids.
|
|
353
|
+
Promise.resolve({
|
|
354
|
+
insertedIds: ['srv-1'],
|
|
355
|
+
updatedIds: [],
|
|
356
|
+
deletedIds: [],
|
|
357
|
+
})
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
const result = await executeBulk({
|
|
361
|
+
collection: 'events',
|
|
362
|
+
ops: { inserts: [{ name: 'Alice' }] },
|
|
363
|
+
createSchema,
|
|
364
|
+
updateSchema,
|
|
365
|
+
access: ACCESS,
|
|
366
|
+
uid: 'user-1',
|
|
367
|
+
userRole: 'user',
|
|
368
|
+
transact,
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
const [prepared] = transact.mock.calls[0];
|
|
372
|
+
expect(prepared.inserts).toEqual([
|
|
373
|
+
{ id: '', row: { name: 'Alice', status: DEFAULT_STATUS_VALUE } },
|
|
374
|
+
]);
|
|
375
|
+
expect(result.insertedIds).toEqual(['srv-1']);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
it('response-schema validation rejects a malformed transact return', async () => {
|
|
379
|
+
const transact = vi.fn(() =>
|
|
380
|
+
Promise.resolve({
|
|
381
|
+
// Missing updatedIds + deletedIds — not a BulkResponse.
|
|
382
|
+
insertedIds: ['a'],
|
|
383
|
+
} as any)
|
|
384
|
+
);
|
|
385
|
+
|
|
386
|
+
await expect(
|
|
387
|
+
executeBulk({
|
|
388
|
+
collection: 'events',
|
|
389
|
+
ops: { inserts: [{ name: 'A' }] },
|
|
390
|
+
createSchema,
|
|
391
|
+
updateSchema,
|
|
392
|
+
access: ACCESS,
|
|
393
|
+
uid: 'u1',
|
|
394
|
+
userRole: 'user',
|
|
395
|
+
transact,
|
|
396
|
+
})
|
|
397
|
+
).rejects.toMatchObject({
|
|
398
|
+
code: 'internal',
|
|
399
|
+
message: expect.stringContaining('unexpected shape'),
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
it('audit fires once with correct counts on success', async () => {
|
|
404
|
+
const transact = vi.fn(okResponse);
|
|
405
|
+
const audit = vi.fn();
|
|
406
|
+
|
|
407
|
+
await executeBulk({
|
|
408
|
+
collection: 'events',
|
|
409
|
+
ops: {
|
|
410
|
+
inserts: [{ name: 'A' }, { name: 'B' }, { name: 'C' }],
|
|
411
|
+
updates: [{ id: 'u1', patch: { name: 'x' } }],
|
|
412
|
+
deletes: ['d1', 'd2'],
|
|
413
|
+
},
|
|
414
|
+
createSchema,
|
|
415
|
+
updateSchema,
|
|
416
|
+
access: ACCESS,
|
|
417
|
+
uid: 'u1',
|
|
418
|
+
userRole: 'user',
|
|
419
|
+
transact,
|
|
420
|
+
audit,
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
expect(audit).toHaveBeenCalledTimes(1);
|
|
424
|
+
expect(audit).toHaveBeenCalledWith('crud.bulk.events', {
|
|
425
|
+
counts: { inserts: 3, updates: 1, deletes: 2 },
|
|
426
|
+
});
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
it('audit does NOT fire when transact throws', async () => {
|
|
430
|
+
const transact = vi.fn(() =>
|
|
431
|
+
Promise.reject(new Error('transaction aborted'))
|
|
432
|
+
);
|
|
433
|
+
const audit = vi.fn();
|
|
434
|
+
|
|
435
|
+
await expect(
|
|
436
|
+
executeBulk({
|
|
437
|
+
collection: 'events',
|
|
438
|
+
ops: { inserts: [{ name: 'A' }] },
|
|
439
|
+
createSchema,
|
|
440
|
+
updateSchema,
|
|
441
|
+
access: ACCESS,
|
|
442
|
+
uid: 'u1',
|
|
443
|
+
userRole: 'user',
|
|
444
|
+
transact,
|
|
445
|
+
audit,
|
|
446
|
+
})
|
|
447
|
+
).rejects.toThrow('transaction aborted');
|
|
448
|
+
|
|
449
|
+
expect(audit).not.toHaveBeenCalled();
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
it('propagates non-DoNotDevError transact failures unchanged (for caller classification)', async () => {
|
|
453
|
+
const boom = new Error('deadlock');
|
|
454
|
+
const transact = vi.fn(() => Promise.reject(boom));
|
|
455
|
+
|
|
456
|
+
await expect(
|
|
457
|
+
executeBulk({
|
|
458
|
+
collection: 'events',
|
|
459
|
+
ops: { inserts: [{ name: 'A' }] },
|
|
460
|
+
createSchema,
|
|
461
|
+
updateSchema,
|
|
462
|
+
access: ACCESS,
|
|
463
|
+
uid: 'u1',
|
|
464
|
+
userRole: 'user',
|
|
465
|
+
transact,
|
|
466
|
+
})
|
|
467
|
+
).rejects.toBe(boom);
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
it('DoNotDevError from transact propagates unchanged', async () => {
|
|
471
|
+
const boom = new DoNotDevError('rpc failure', 'internal');
|
|
472
|
+
const transact = vi.fn(() => Promise.reject(boom));
|
|
473
|
+
|
|
474
|
+
await expect(
|
|
475
|
+
executeBulk({
|
|
476
|
+
collection: 'events',
|
|
477
|
+
ops: { inserts: [{ name: 'A' }] },
|
|
478
|
+
createSchema,
|
|
479
|
+
updateSchema,
|
|
480
|
+
access: ACCESS,
|
|
481
|
+
uid: 'u1',
|
|
482
|
+
userRole: 'user',
|
|
483
|
+
transact,
|
|
484
|
+
})
|
|
485
|
+
).rejects.toBe(boom);
|
|
486
|
+
});
|
|
487
|
+
});
|
|
File without changes
|
|
@@ -76,7 +76,9 @@ describe('toTimestamp', () => {
|
|
|
76
76
|
it('converts ISO string to timestamp', () => {
|
|
77
77
|
const ts = toTimestamp('2026-01-15T12:00:00.000Z');
|
|
78
78
|
|
|
79
|
-
expect(ts.seconds).toBe(
|
|
79
|
+
expect(ts.seconds).toBe(
|
|
80
|
+
Math.floor(new Date('2026-01-15T12:00:00.000Z').getTime() / 1000)
|
|
81
|
+
);
|
|
80
82
|
});
|
|
81
83
|
|
|
82
84
|
it('converts Date object to timestamp', () => {
|
|
@@ -87,11 +89,15 @@ describe('toTimestamp', () => {
|
|
|
87
89
|
});
|
|
88
90
|
|
|
89
91
|
it('throws for invalid date string', () => {
|
|
90
|
-
expect(() => toTimestamp('not-a-date')).toThrow(
|
|
92
|
+
expect(() => toTimestamp('not-a-date')).toThrow(
|
|
93
|
+
'Failed to convert to timestamp'
|
|
94
|
+
);
|
|
91
95
|
});
|
|
92
96
|
|
|
93
97
|
it('throws for invalid Date object', () => {
|
|
94
|
-
expect(() => toTimestamp(new Date('invalid'))).toThrow(
|
|
98
|
+
expect(() => toTimestamp(new Date('invalid'))).toThrow(
|
|
99
|
+
'Failed to convert to timestamp'
|
|
100
|
+
);
|
|
95
101
|
});
|
|
96
102
|
});
|
|
97
103
|
|
|
File without changes
|
|
@@ -66,7 +66,9 @@ describe('validateCollectionName (internal)', () => {
|
|
|
66
66
|
});
|
|
67
67
|
|
|
68
68
|
it('rejects empty string', () => {
|
|
69
|
-
expect(() => validateCollectionName('')).toThrow(
|
|
69
|
+
expect(() => validateCollectionName('')).toThrow(
|
|
70
|
+
'Collection name is required'
|
|
71
|
+
);
|
|
70
72
|
});
|
|
71
73
|
|
|
72
74
|
it('rejects non-string', () => {
|
|
@@ -79,11 +81,15 @@ describe('validateCollectionName (internal)', () => {
|
|
|
79
81
|
});
|
|
80
82
|
|
|
81
83
|
it('rejects path traversal with slash', () => {
|
|
82
|
-
expect(() => validateCollectionName('a/b')).toThrow(
|
|
84
|
+
expect(() => validateCollectionName('a/b')).toThrow(
|
|
85
|
+
'Invalid collection name'
|
|
86
|
+
);
|
|
83
87
|
});
|
|
84
88
|
|
|
85
89
|
it('rejects path traversal with double dots', () => {
|
|
86
|
-
expect(() => validateCollectionName('a..b')).toThrow(
|
|
90
|
+
expect(() => validateCollectionName('a..b')).toThrow(
|
|
91
|
+
'Invalid collection name'
|
|
92
|
+
);
|
|
87
93
|
});
|
|
88
94
|
|
|
89
95
|
it('rejects internal collections starting with underscore', () => {
|