Improve server and client operations API (#2044)

This commit is contained in:
Filip Sodić 2024-06-22 13:53:10 +02:00 committed by GitHub
parent 56af0635c3
commit 52277d8b15
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
186 changed files with 2779 additions and 666 deletions

View File

@ -5,6 +5,7 @@
### 🎉 New Features
- Simplified Auth User API: Introduced a simpler API for accessing user auth fields (for example `username`, `email`, `isEmailVerified`) directly on the `user` object, eliminating the need for helper functions.
- Improved the API for calling Operations (Queries and Actions) directly on both the client and the server.
- Improved API for calling Operations (Queries and Actions) directly.
- Auth Hooks: you can now hook into the auth process with `onBeforeSignup`, `onAfterSignup` hooks. You can also modify the OAuth redirect URL with `onBeforeOAuthRedirect` hook.

View File

@ -37,7 +37,11 @@ export function createAction<BackendAction extends GenericBackendOperation>(
const action = (args) => internalAction(args, [])
action.internal = internalAction
return action as ActionFor<BackendAction>
// NOTE: I'm not sure why unknown is necessary here,
// it might have something to do with functions allowing evolving types,
// // while objects to not:
// https://www.typescriptlang.org/play/?#code/MYewdgzgLgBCBGArGBeGBvGBDAXDA5AGYgj4wC+AUAogHTyoHxYBO+llA9JzIQK5hgUAJbhsAG3EgA7hGxgYAUwBuIccuFgA5jCgBPAA6KY8PrBqKhMACYhFcsCCiVQkWPwVoAFAEpUAPgJiUkoPekZ8ZjYgA
return action as unknown as ActionFor<BackendAction>
}
// PRIVATE API

View File

@ -10,4 +10,4 @@ export const {= operationName =}: ActionFor<{= operationTypeName =}> = createAct
'{= actionRoute =}',
{=& entitiesArray =},
)
{=/ actions =}
{=/ actions =}

View File

@ -72,7 +72,11 @@ export function useAction<Input = unknown, Output = unknown>(
// clearly separate our opinionated API from React Query's lower-level
// advanced API (which users can also use)
const mutation = useMutation(mutationFn, options);
return (args) => mutation.mutateAsync(args);
// This assertion is necessary because, when the Input is void, we want to
// present the function as not accepting a payload (which isn't consistent
// with how it's defined).
return ((args: Input) => mutation.mutateAsync(args)) as typeof actionFn;
}
// PUBLIC API
@ -200,7 +204,7 @@ function makeOptimisticUpdateMutationFn<Input, Output, CachedData>(
CachedData
>[]
): typeof actionFn {
return function performActionWithOptimisticUpdates(item) {
return (function performActionWithOptimisticUpdates(item?: Input) {
const specificOptimisticUpdateDefinitions = optimisticUpdateDefinitions.map(
(generalDefinition) =>
getOptimisticUpdateDefinitionForSpecificItem(generalDefinition, item)
@ -209,7 +213,10 @@ function makeOptimisticUpdateMutationFn<Input, Output, CachedData>(
item,
specificOptimisticUpdateDefinitions
);
};
// This assertion is necessary because, when the Input is void, we want to
// present the function as not accepting a payload (which isn't consistent
// with how it's defined).
}) as typeof actionFn;
}
/**

View File

@ -1,6 +1,6 @@
import { Route } from 'wasp/client'
import type { _Awaited, _ReturnType } from 'wasp/universal/types'
import type {
import type {
GenericBackendOperation,
GenericOperationRpc,
OperationRpcFor,
@ -20,9 +20,9 @@ export function makeQueryCacheKey<Input, Output>(
query: Query<Input, Output>,
payload: Input
): (string | Input)[] {
return payload !== undefined ?
[...query.queryCacheKey, payload]
: query.queryCacheKey
return payload !== undefined ?
[...query.queryCacheKey, payload]
: query.queryCacheKey
}
// PRIVATE API (unsed in SDK)
@ -33,7 +33,7 @@ export function createQuery<BackendQuery extends GenericBackendOperation>(
const queryRoute = makeOperationRoute(relativeQueryPath)
const queryCacheKey = [relativeQueryPath]
const queryFn: QueryFunctionFor<BackendQuery> = async (queryArgs) => {
const queryFn = (async (queryArgs) => {
const serverResult = await callOperation(queryRoute, queryArgs)
// todo: The full queryCacheKey is constructed in two places, both here and
// inside the useQuery hook. See
@ -43,7 +43,10 @@ export function createQuery<BackendQuery extends GenericBackendOperation>(
(result, update) => update(result),
serverResult,
)
}
// This assertion is necessary because, when the Input is void, we want to
// present the function as not accepting a payload (which isn't consistent
// with how it's defined).
}) as QueryFunctionFor<BackendQuery>
return buildAndRegisterQuery(
queryFn,
@ -54,12 +57,12 @@ export function createQuery<BackendQuery extends GenericBackendOperation>(
// PRIVATE API (used in SDK)
export function buildAndRegisterQuery<QF extends GenericOperationRpc>(
queryFn: QF,
{ queryCacheKey, queryRoute, entitiesUsed }:
{ queryCacheKey: string[], queryRoute: Route, entitiesUsed: string[] }
{ queryCacheKey, queryRoute, entitiesUsed }:
{ queryCacheKey: string[], queryRoute: Route, entitiesUsed: string[] }
): QueryForFunction<QF> {
const query = queryFn as QueryForFunction<QF>
query.queryCacheKey = queryCacheKey
query.queryCacheKey = queryCacheKey
query.route = queryRoute
addResourcesUsedByQuery(query.queryCacheKey, entitiesUsed)
@ -77,7 +80,7 @@ export type QueryFor<BackendQuery extends GenericBackendOperation> =
/**
* Constructs the client Query function type from the type of the Query's
* definition on the backend.
*/
*/
type QueryFunctionFor<BackendQuery extends GenericBackendOperation> =
OperationRpcFor<BackendQuery>

View File

@ -77,4 +77,6 @@ export type GenericOperationRpc = (args: never) => Promise<unknown>
// Read this to understand the type: https://github.com/wasp-lang/wasp/pull/1090#discussion_r1159732471
type ClientOperation<Input, Output> = [Input] extends [never]
? (args?: unknown) => Promise<Output>
: (args: Input) => Promise<Output>;
: [Input] extends [void]
? () => Promise<Output>
: (args: Input) => Promise<Output>

View File

@ -1,41 +1,52 @@
{{={= =}=}}
import { type Expand } from 'wasp/universal/types';
import { type Expand } from 'wasp/universal/types'
import { type Request, type Response } from 'express'
import { type ParamsDictionary as ExpressParams, type Query as ExpressQuery } from 'express-serve-static-core'
import {
type ParamsDictionary as ExpressParams,
type Query as ExpressQuery,
} from 'express-serve-static-core'
import { prisma } from 'wasp/server'
{=# isAuthEnabled =}
import {
type {= authIdentityEntityName =},
} from "wasp/entities"
import {
type EmailProviderData,
type UsernameProviderData,
type OAuthProviderData,
} from 'wasp/auth/utils'
import { type AuthUser } from 'wasp/auth'
{=/ isAuthEnabled =}
import { type _Entity } from "./taggedEntities"
import { type Payload } from "./serialization";
import { type _Entity } from './taggedEntities'
import { type Payload } from './serialization'
export * from "./taggedEntities"
export * from "./serialization"
export type Query<Entities extends _Entity[], Input extends Payload, Output extends Payload> =
Operation<Entities, Input, Output>
export type UnauthenticatedQueryDefinition<
Entities extends _Entity[],
Input extends Payload,
Output extends Payload
> = UnauthenticatedOperationDefinition<Entities, Input, Output>
export type Action<Entities extends _Entity[], Input extends Payload, Output extends Payload> =
Operation<Entities, Input, Output>
export type UnauthenticatedActionDefinition<
Entities extends _Entity[],
Input extends Payload,
Output extends Payload
> = UnauthenticatedOperationDefinition<Entities, Input, Output>
{=# isAuthEnabled =}
export type AuthenticatedQuery<Entities extends _Entity[], Input extends Payload, Output extends Payload> =
AuthenticatedOperation<Entities, Input, Output>
export type AuthenticatedQueryDefinition<
Entities extends _Entity[],
Input extends Payload,
Output extends Payload
> = AuthenticatedOperationDefinition<Entities, Input, Output>
export type AuthenticatedAction<Entities extends _Entity[], Input extends Payload, Output extends Payload> =
AuthenticatedOperation<Entities, Input, Output>
export type AuthenticatedActionDefinition<
Entities extends _Entity[],
Input extends Payload,
Output extends Payload
> = AuthenticatedOperationDefinition<Entities, Input, Output>
type AuthenticatedOperation<Entities extends _Entity[], Input extends Payload, Output extends Payload> = (
export type AuthenticatedOperationDefinition<
Entities extends _Entity[],
Input extends Payload,
Output extends Payload
> = (
args: Input,
context: ContextWithUser<Entities>,
context: ContextWithUser<Entities>
) => Output | Promise<Output>
export type AuthenticatedApi<
@ -52,10 +63,11 @@ export type AuthenticatedApi<
) => void
{=/ isAuthEnabled =}
type Operation<Entities extends _Entity[], Input, Output> = (
args: Input,
context: Context<Entities>,
) => Output | Promise<Output>
export type UnauthenticatedOperationDefinition<
Entities extends _Entity[],
Input extends Payload,
Output extends Payload
> = (args: Input, context: Context<Entities>) => Output | Promise<Output>
export type Api<
Entities extends _Entity[],
@ -70,7 +82,7 @@ export type Api<
context: Context<Entities>,
) => void
type EntityMap<Entities extends _Entity[]> = {
export type EntityMap<Entities extends _Entity[]> = {
[EntityName in Entities[number]["_entityName"]]: PrismaDelegate[EntityName]
}
@ -85,7 +97,9 @@ type Context<Entities extends _Entity[]> = Expand<{
}>
{=# isAuthEnabled =}
type ContextWithUser<Entities extends _Entity[]> = Expand<Context<Entities> & { user?: AuthUser }>
type ContextWithUser<Entities extends _Entity[]> = Expand<
Context<Entities> & { user?: AuthUser }
>
export type { ProviderName } from 'wasp/auth/utils'
{=/ isAuthEnabled =}

View File

@ -1,12 +1,12 @@
{{={= =}=}}
import type {
{=# isAuthEnabled =}
AuthenticatedAction,
AuthenticatedQuery,
AuthenticatedActionDefinition,
AuthenticatedQueryDefinition,
{=/ isAuthEnabled =}
{=^ isAuthEnabled =}
Action,
Query,
ActionDefinition,
QueryDefinition,
{=/ isAuthEnabled =}
_{= crud.entityUpper =},
} from "wasp/server/_types";

View File

@ -1,28 +1,41 @@
{{={= =}=}}
import { prisma } from 'wasp/server'
{=! TODO: This template is exactly the same at the moment as one for queries,
consider in the future if it is worth removing this duplication. =}
{=! TODO: This will generate multiple import statements even though they're
importing symbols from the same file. We should improve our importing machinery
to support multiple imports from the same file =}
import { prisma } from 'wasp/server'
import {
type UnauthenticatedOperationFor,
createUnauthenticatedOperation,
{=# isAuthEnabled =}
type AuthenticatedOperationFor,
createAuthenticatedOperation,
{=/ isAuthEnabled =}
} from '../wrappers.js'
{=# operations =}
{=& jsFn.importStatement =}
{=/ operations =}
{=# operations =}
// PRIVATE API
export type {= operationTypeName =} = typeof {= jsFn.importIdentifier =}
export type {= operationTypeName =} = typeof {= jsFn.importIdentifier =}
// PUBLIC API
export const {= operationName =} = async (args, context) => {
return ({= jsFn.importIdentifier =} as any)(args, {
...context,
entities: {
{=# usesAuth =}
export const {= operationName =}: AuthenticatedOperationFor<{= operationTypeName =}> =
createAuthenticatedOperation(
{=/ usesAuth =}
{=^ usesAuth =}
export const {= operationName =}: UnauthenticatedOperationFor<{= operationTypeName =}> =
createUnauthenticatedOperation(
{=/ usesAuth =}
{= jsFn.importIdentifier =},
{
{=# entities =}
{= name =}: prisma.{= prismaIdentifier =},
{=/ entities =}
},
})
}
)
{=/ operations =}

View File

@ -6,10 +6,10 @@ import {
type {= internalTypeName =},
{=/ allEntities =}
{=# shouldImportNonAuthenticatedOperation =}
type Action,
type UnauthenticatedActionDefinition,
{=/ shouldImportNonAuthenticatedOperation =}
{=# shouldImportAuthenticatedOperation =}
type AuthenticatedAction,
type AuthenticatedActionDefinition,
{=/ shouldImportAuthenticatedOperation =}
type Payload,
} from 'wasp/server/_types'
@ -18,10 +18,10 @@ import {
// PUBLIC API
export type {= typeName =}<Input extends Payload = never, Output extends Payload = Payload> =
{=# usesAuth =}
AuthenticatedAction<
AuthenticatedActionDefinition<
{=/ usesAuth =}
{=^ usesAuth =}
Action<
UnauthenticatedActionDefinition<
{=/ usesAuth =}
[
{=# entities =}

View File

@ -1,28 +1,42 @@
{{={= =}=}}
import { prisma } from 'wasp/server'
{=! TODO: This template is exactly the same at the moment as one for actions,
consider in the future if it is worth removing this duplication. =}
{=! TODO: This will generate multiple import statements even though they're
importing symbols from the same file. We should improve our importing machinery
to support multiple imports from the same file =}
import { prisma } from 'wasp/server'
import {
type UnauthenticatedOperationFor,
createUnauthenticatedOperation,
{=# isAuthEnabled =}
type AuthenticatedOperationFor,
createAuthenticatedOperation,
{=/ isAuthEnabled =}
} from '../wrappers.js'
{=# operations =}
{=& jsFn.importStatement =}
{=/ operations =}
{=# operations =}
// PRIVATE API
export type {= operationTypeName =} = typeof {= jsFn.importIdentifier =}
export type {= operationTypeName =} = typeof {= jsFn.importIdentifier =}
// PUBLIC API
export const {= operationName =} = async (args, context) => {
return ({= jsFn.importIdentifier =} as any)(args, {
...context,
entities: {
{=# usesAuth =}
export const {= operationName =}: AuthenticatedOperationFor<{= operationTypeName =}> =
createAuthenticatedOperation(
{=/ usesAuth =}
{=^ usesAuth =}
export const {= operationName =}: UnauthenticatedOperationFor<{= operationTypeName =}> =
createUnauthenticatedOperation(
{=/ usesAuth =}
{= jsFn.importIdentifier =},
{
{=# entities =}
{= name =}: prisma.{= prismaIdentifier =},
{=/ entities =}
},
})
}
)
{=/ operations =}

View File

@ -7,10 +7,10 @@ import {
type {= internalTypeName =},
{=/ allEntities =}
{=# shouldImportNonAuthenticatedOperation =}
type Query,
type UnauthenticatedQueryDefinition,
{=/ shouldImportNonAuthenticatedOperation =}
{=# shouldImportAuthenticatedOperation =}
type AuthenticatedQuery,
type AuthenticatedQueryDefinition,
{=/ shouldImportAuthenticatedOperation =}
type Payload,
} from 'wasp/server/_types'
@ -19,10 +19,10 @@ import {
// PUBLIC API
export type {= typeName =}<Input extends Payload = never, Output extends Payload = Payload> =
{=# usesAuth =}
AuthenticatedQuery<
AuthenticatedQueryDefinition<
{=/ usesAuth =}
{=^ usesAuth =}
Query<
UnauthenticatedQueryDefinition<
{=/ usesAuth =}
[
{=# entities =}

View File

@ -0,0 +1,223 @@
{{={= =}=}}
import { _Awaited, _ReturnType } from '../../universal/types'
{=# isAuthEnabled =}
import { type AuthUser } from 'wasp/auth'
{=/ isAuthEnabled =}
import {
_Entity,
{=# isAuthEnabled =}
AuthenticatedOperationDefinition,
{=/ isAuthEnabled =}
UnauthenticatedOperationDefinition,
Payload,
} from '../_types'
// PRIVATE API (used in SDK)
// Explanation:
// - Custom `_Awaited` and `_ReturnType` - Read the comments above their
// definitions.
// - `Parameters<OperationDefinition> extends []` - Same reason as described here:
// https://github.com/wasp-lang/wasp/pull/1992/files#r1583040080
/**
* Constructs the unauthenticated operation's server-side API type from its
* definition.
*
* @template OperationDefinition The type of the unauthenticated operation's
* definition.
*/
export type UnauthenticatedOperationFor<
OperationDefinition extends GenericUnauthenticatedOperationDefinition
> = Parameters<OperationDefinition> extends []
? UnauthenticatedOperation<void, _Awaited<_ReturnType<OperationDefinition>>>
: UnauthenticatedOperation<
Parameters<OperationDefinition>[0],
_Awaited<_ReturnType<OperationDefinition>>
>
// PRIVATE API (used in SDK)
/**
* Creates the server-side API for an unauthenticated operation.
*
* @template OperationDefinition The type of the unauthenticated operation's definition.
* @param userOperation The unauthenticated operation's definition.
* @param entities The unauthenticated operation's entity map .
* @returns The server-side API for the provided unauthenticated operation.
*/
export function createUnauthenticatedOperation<
OperationDefinition extends GenericUnauthenticatedOperationDefinition
>(
userOperation: OperationDefinition,
entities: EntityMapFor<OperationDefinition>
): UnauthenticatedOperationFor<OperationDefinition> {
async function operation(payload: Parameters<OperationDefinition>[0]) {
return userOperation(payload, {
entities,
})
}
// This assertion is necessary because, when the Input is void, we want to present
// the function as not accepting a payload (which isn't consistent with how
// it's defined).
return operation as UnauthenticatedOperationFor<OperationDefinition>
}
{=# isAuthEnabled =}
// PRIVATE API (used in SDK)
// Explanation:
// - Custom `_Awaited` and `_ReturnType` - Read the comments above their
// definitions.
// - `Parameters<OperationDefinition> extends []` - Same reason as described here:
// https://github.com/wasp-lang/wasp/pull/1992/files#r1583040080
/**
* Constructs the authenticated operation's server-side API type from its
* definition.
*
* @template OperationDefinition The type of the authenticated operation's
* definition.
*/
export type AuthenticatedOperationFor<
OperationDefinition extends GenericAuthenticatedOperationDefinition
> = Parameters<OperationDefinition> extends []
? AuthenticatedOperation<void, _Awaited<_ReturnType<OperationDefinition>>>
: AuthenticatedOperation<
Parameters<OperationDefinition>[0],
_Awaited<_ReturnType<OperationDefinition>>
>
/**
* The type of the context users must pass when calling an authenticated
* operation's server-side API.
*/
export type AuthenticatedOperationContext = { user: AuthUser }
// PRIVATE API (used in SDK)
/**
* Creates the server-side API for an authenticated operation.
*
* @template OperationDefinition The type of the authenticated operation's definition.
* @param userOperation The authenticated operation's definition.
* @param entities The authenticated operation's entity map .
* @returns The server-side API for the provided authenticated operation.
*/
export function createAuthenticatedOperation<
OperationDefinition extends GenericAuthenticatedOperationDefinition
>(
userOperation: OperationDefinition,
entities: EntityMapFor<OperationDefinition>
): AuthenticatedOperationFor<OperationDefinition> {
async function operation(...args: AuthenticatedOperationArgsFor<OperationDefinition>) {
// To understand this function and its limitations, read
// https://github.com/wasp-lang/wasp/issues/2050
if (args.length < 1) {
// No arguments sent -> no user and no payload specified -> there's no way this was called correctly.
throw new Error(`
You called the operation without arguments, which is a mistake.
Check your definition and read the docs to understand what you need to send:
https://wasp-lang.dev/docs/data-model/operations/overview
`
)
} else if (includesPayload(args)) {
// Two arguments sent -> the first argument is the payload, the second is the context.
const [payload, context] = args
return userOperation(payload as Parameters<OperationDefinition>[0], {
...context,
entities,
})
} else {
// One argument sent -> the first and only argument is the user.
const [context] = args
return userOperation(undefined as Parameters<OperationDefinition>[0], {
...context,
entities,
})
}
}
return operation as AuthenticatedOperationFor<OperationDefinition>
}
/**
* Returns a boolean carrying compiler type information about whether the
* provided arguments array (of an authenticated operation) includes a payload.
*
* To understand why "two arguments" means "includes payload", read
* https://github.com/wasp-lang/wasp/issues/2050
*
* @template Input The type of the payload the operation expects.
* @param args The arguments array for an authenticated operation.
* @returns true if the arguments array includes a payload, false otherwise.
*/
function includesPayload<Input>(
args: [AuthenticatedOperationContext] | [Input, AuthenticatedOperationContext]
): args is [Input, AuthenticatedOperationContext] {
return args.length === 2
}
/**
* Constructs the type of the arguments array for an authenticated operation
* based on the type of its definition.
*/
type AuthenticatedOperationArgsFor<Op extends GenericAuthenticatedOperationDefinition> =
Parameters<AuthenticatedOperationFor<Op>>
/**
* Constructs the type for an authenticated operation's server-side API.
*
* @template Input The type of the payload the operation expects (must be
* `void` if the operation doesn't expect a payload).
* @template Output The type of the operation's return value.
*/
type AuthenticatedOperation<Input, Output> =
[Input] extends [never]
? (args: unknown, context: { user: AuthUser }) => Promise<Output>
: [Input] extends [void]
? (context: { user: AuthUser }) => Promise<Output>
: (args: Input, context: { user: AuthUser }) => Promise<Output>
/**
* The principal type for an authenticated operation's definition (i.e., all
* authenticated operation definition types are a subtype of this type).
*
*/
type GenericAuthenticatedOperationDefinition = AuthenticatedOperationDefinition<
// NOTE(filip): Not quite sure I understand what's going on with Variance here.
_Entity[],
never,
Payload
>
{=/ isAuthEnabled =}
/**
* Constructs the type for an unauthenticated operation's server-side API.
*
* @template Input The type of the payload the operation expects (must be
* `void` if the operation doesn't expect a payload).
* @template Output The type of the operation's return value.
*/
type UnauthenticatedOperation<Input, Output> =
[Input] extends [never]
? (args: unknown) => Promise<Output>
: [Input] extends [void]
? () => Promise<Output>
: (args: Input) => Promise<Output>
/**
* The principal type for an unauthenticated operation's definition (i.e., all
* unauthenticated operation definition types are a subtype of this type).
*
*/
type GenericUnauthenticatedOperationDefinition = UnauthenticatedOperationDefinition<
// NOTE(filip): Not quite sure I understand what's going on with Variance here.
_Entity[],
never,
Payload
>
/**
* Queries the entity map from the type of the operation's definition.
*
* @template OperationDefinition The type of the operation's definition.
*/
type EntityMapFor<OperationDefinition extends GenericUnauthenticatedOperationDefinition> =
Parameters<OperationDefinition>[1]["entities"]

View File

@ -16,5 +16,3 @@ export default async function (args, context) {
},
})
}
export type {= operationTypeName =} = typeof {= jsFn.importIdentifier =}

View File

@ -16,5 +16,3 @@ export default async function (args, context) {
},
})
}
export type {= operationTypeName =} = typeof {= jsFn.importIdentifier =}

View File

@ -144,6 +144,9 @@ waspBuild/.wasp/build/sdk/wasp/dist/server/operations/queries/index.js.map
waspBuild/.wasp/build/sdk/wasp/dist/server/operations/queries/types.d.ts
waspBuild/.wasp/build/sdk/wasp/dist/server/operations/queries/types.js
waspBuild/.wasp/build/sdk/wasp/dist/server/operations/queries/types.js.map
waspBuild/.wasp/build/sdk/wasp/dist/server/operations/wrappers.d.ts
waspBuild/.wasp/build/sdk/wasp/dist/server/operations/wrappers.js
waspBuild/.wasp/build/sdk/wasp/dist/server/operations/wrappers.js.map
waspBuild/.wasp/build/sdk/wasp/dist/server/types/index.d.ts
waspBuild/.wasp/build/sdk/wasp/dist/server/types/index.js
waspBuild/.wasp/build/sdk/wasp/dist/server/types/index.js.map
@ -179,6 +182,7 @@ waspBuild/.wasp/build/sdk/wasp/server/operations/actions/types.ts
waspBuild/.wasp/build/sdk/wasp/server/operations/index.ts
waspBuild/.wasp/build/sdk/wasp/server/operations/queries/index.ts
waspBuild/.wasp/build/sdk/wasp/server/operations/queries/types.ts
waspBuild/.wasp/build/sdk/wasp/server/operations/wrappers.ts
waspBuild/.wasp/build/sdk/wasp/server/types/index.ts
waspBuild/.wasp/build/sdk/wasp/server/utils.ts
waspBuild/.wasp/build/sdk/wasp/tsconfig.json
@ -366,6 +370,9 @@ waspBuild/.wasp/out/sdk/wasp/dist/server/operations/queries/index.js.map
waspBuild/.wasp/out/sdk/wasp/dist/server/operations/queries/types.d.ts
waspBuild/.wasp/out/sdk/wasp/dist/server/operations/queries/types.js
waspBuild/.wasp/out/sdk/wasp/dist/server/operations/queries/types.js.map
waspBuild/.wasp/out/sdk/wasp/dist/server/operations/wrappers.d.ts
waspBuild/.wasp/out/sdk/wasp/dist/server/operations/wrappers.js
waspBuild/.wasp/out/sdk/wasp/dist/server/operations/wrappers.js.map
waspBuild/.wasp/out/sdk/wasp/dist/server/types/index.d.ts
waspBuild/.wasp/out/sdk/wasp/dist/server/types/index.js
waspBuild/.wasp/out/sdk/wasp/dist/server/types/index.js.map
@ -401,6 +408,7 @@ waspBuild/.wasp/out/sdk/wasp/server/operations/actions/types.ts
waspBuild/.wasp/out/sdk/wasp/server/operations/index.ts
waspBuild/.wasp/out/sdk/wasp/server/operations/queries/index.ts
waspBuild/.wasp/out/sdk/wasp/server/operations/queries/types.ts
waspBuild/.wasp/out/sdk/wasp/server/operations/wrappers.ts
waspBuild/.wasp/out/sdk/wasp/server/types/index.ts
waspBuild/.wasp/out/sdk/wasp/server/utils.ts
waspBuild/.wasp/out/sdk/wasp/tsconfig.json

View File

@ -32,7 +32,7 @@
"file",
"../out/sdk/wasp/client/operations/actions/core.ts"
],
"d19dba04947e4015af69d90dd160ec5f4ed020bfa905bc37bcd5d980517097ae"
"ff3597c5f07015adf4dcf5cf6043d054989e76522fd59eb94bdaa34e9c9ea95f"
],
[
[
@ -46,7 +46,7 @@
"file",
"../out/sdk/wasp/client/operations/hooks.ts"
],
"18b73aae68fbe6774d4a9929e48b3d9fbd8acae9b811b31a076547f463e6e620"
"d1a8fccfb8207476b90708e8285d1455b33ff4e446749b33c3eb1a54dcfe2d41"
],
[
[
@ -81,7 +81,7 @@
"file",
"../out/sdk/wasp/client/operations/queries/core.ts"
],
"2229320d3541802817d12f2dc1226a0e683bf058ab27150ae4ba661c6891d257"
"7f842b7add5a2949a49981dac64dd5951457eb5b9d3c555f25f6e4f11c04f3b4"
],
[
[
@ -102,7 +102,7 @@
"file",
"../out/sdk/wasp/client/operations/rpc.ts"
],
"a396d0014651837eae36f83d5c36e730e6d389ee7ff41e72206cc6936419d576"
"63fb0670b2ccff4ad005bbb76597572a60e01f31b739d7bc764bb59c4f3c53d4"
],
[
[
@ -214,7 +214,7 @@
"file",
"../out/sdk/wasp/server/_types/index.ts"
],
"2eb94c60f2031ae3ea023de5aa938b3aeabba31388a7f8bdcdee432bbef3f517"
"e19d9927bb6f9d4a95641c01d3488d45dad5c8bf708b6573401e8ee9f4067995"
],
[
[
@ -270,7 +270,7 @@
"file",
"../out/sdk/wasp/server/operations/actions/index.ts"
],
"c67a0c7d8946f5c465edea2de78e78537384bd6f30ec4f4fd6dfe58243f4f36a"
"35fa55dbb38aa52924082f825b80c4b41be7371934466f6797aeef02b70baa31"
],
[
[
@ -291,7 +291,7 @@
"file",
"../out/sdk/wasp/server/operations/queries/index.ts"
],
"c67a0c7d8946f5c465edea2de78e78537384bd6f30ec4f4fd6dfe58243f4f36a"
"35fa55dbb38aa52924082f825b80c4b41be7371934466f6797aeef02b70baa31"
],
[
[
@ -300,6 +300,13 @@
],
"19f72a3a37efd1e29b0793caa7f379494ad236bb513c8c8804b5a8d305c45196"
],
[
[
"file",
"../out/sdk/wasp/server/operations/wrappers.ts"
],
"4f3ffd00d845664a0122a24d2a12279c0febd744214c7167e7d9dea41330e107"
],
[
[
"file",

View File

@ -37,7 +37,11 @@ export function createAction<BackendAction extends GenericBackendOperation>(
const action = (args) => internalAction(args, [])
action.internal = internalAction
return action as ActionFor<BackendAction>
// NOTE: I'm not sure why unknown is necessary here,
// it might have something to do with functions allowing evolving types,
// // while objects to not:
// https://www.typescriptlang.org/play/?#code/MYewdgzgLgBCBGArGBeGBvGBDAXDA5AGYgj4wC+AUAogHTyoHxYBO+llA9JzIQK5hgUAJbhsAG3EgA7hGxgYAUwBuIccuFgA5jCgBPAA6KY8PrBqKhMACYhFcsCCiVQkWPwVoAFAEpUAPgJiUkoPekZ8ZjYgA
return action as unknown as ActionFor<BackendAction>
}
// PRIVATE API

View File

@ -72,7 +72,11 @@ export function useAction<Input = unknown, Output = unknown>(
// clearly separate our opinionated API from React Query's lower-level
// advanced API (which users can also use)
const mutation = useMutation(mutationFn, options);
return (args) => mutation.mutateAsync(args);
// This assertion is necessary because, when the Input is void, we want to
// present the function as not accepting a payload (which isn't consistent
// with how it's defined).
return ((args: Input) => mutation.mutateAsync(args)) as typeof actionFn;
}
// PUBLIC API
@ -200,7 +204,7 @@ function makeOptimisticUpdateMutationFn<Input, Output, CachedData>(
CachedData
>[]
): typeof actionFn {
return function performActionWithOptimisticUpdates(item) {
return (function performActionWithOptimisticUpdates(item?: Input) {
const specificOptimisticUpdateDefinitions = optimisticUpdateDefinitions.map(
(generalDefinition) =>
getOptimisticUpdateDefinitionForSpecificItem(generalDefinition, item)
@ -209,7 +213,10 @@ function makeOptimisticUpdateMutationFn<Input, Output, CachedData>(
item,
specificOptimisticUpdateDefinitions
);
};
// This assertion is necessary because, when the Input is void, we want to
// present the function as not accepting a payload (which isn't consistent
// with how it's defined).
}) as typeof actionFn;
}
/**

View File

@ -1,6 +1,6 @@
import { Route } from 'wasp/client'
import type { _Awaited, _ReturnType } from 'wasp/universal/types'
import type {
import type {
GenericBackendOperation,
GenericOperationRpc,
OperationRpcFor,
@ -20,9 +20,9 @@ export function makeQueryCacheKey<Input, Output>(
query: Query<Input, Output>,
payload: Input
): (string | Input)[] {
return payload !== undefined ?
[...query.queryCacheKey, payload]
: query.queryCacheKey
return payload !== undefined ?
[...query.queryCacheKey, payload]
: query.queryCacheKey
}
// PRIVATE API (unsed in SDK)
@ -33,7 +33,7 @@ export function createQuery<BackendQuery extends GenericBackendOperation>(
const queryRoute = makeOperationRoute(relativeQueryPath)
const queryCacheKey = [relativeQueryPath]
const queryFn: QueryFunctionFor<BackendQuery> = async (queryArgs) => {
const queryFn = (async (queryArgs) => {
const serverResult = await callOperation(queryRoute, queryArgs)
// todo: The full queryCacheKey is constructed in two places, both here and
// inside the useQuery hook. See
@ -43,7 +43,10 @@ export function createQuery<BackendQuery extends GenericBackendOperation>(
(result, update) => update(result),
serverResult,
)
}
// This assertion is necessary because, when the Input is void, we want to
// present the function as not accepting a payload (which isn't consistent
// with how it's defined).
}) as QueryFunctionFor<BackendQuery>
return buildAndRegisterQuery(
queryFn,
@ -54,12 +57,12 @@ export function createQuery<BackendQuery extends GenericBackendOperation>(
// PRIVATE API (used in SDK)
export function buildAndRegisterQuery<QF extends GenericOperationRpc>(
queryFn: QF,
{ queryCacheKey, queryRoute, entitiesUsed }:
{ queryCacheKey: string[], queryRoute: Route, entitiesUsed: string[] }
{ queryCacheKey, queryRoute, entitiesUsed }:
{ queryCacheKey: string[], queryRoute: Route, entitiesUsed: string[] }
): QueryForFunction<QF> {
const query = queryFn as QueryForFunction<QF>
query.queryCacheKey = queryCacheKey
query.queryCacheKey = queryCacheKey
query.route = queryRoute
addResourcesUsedByQuery(query.queryCacheKey, entitiesUsed)
@ -77,7 +80,7 @@ export type QueryFor<BackendQuery extends GenericBackendOperation> =
/**
* Constructs the client Query function type from the type of the Query's
* definition on the backend.
*/
*/
type QueryFunctionFor<BackendQuery extends GenericBackendOperation> =
OperationRpcFor<BackendQuery>

View File

@ -77,4 +77,6 @@ export type GenericOperationRpc = (args: never) => Promise<unknown>
// Read this to understand the type: https://github.com/wasp-lang/wasp/pull/1090#discussion_r1159732471
type ClientOperation<Input, Output> = [Input] extends [never]
? (args?: unknown) => Promise<Output>
: (args: Input) => Promise<Output>;
: [Input] extends [void]
? () => Promise<Output>
: (args: Input) => Promise<Output>

View File

@ -26,6 +26,10 @@ export function createAction(relativeActionRoute, entitiesUsed) {
// we can always hide it using a Symbol.
const action = (args) => internalAction(args, []);
action.internal = internalAction;
// NOTE: I'm not sure why unknown is necessary here,
// it might have something to do with functions allowing evolving types,
// // while objects to not:
// https://www.typescriptlang.org/play/?#code/MYewdgzgLgBCBGArGBeGBvGBDAXDA5AGYgj4wC+AUAogHTyoHxYBO+llA9JzIQK5hgUAJbhsAG3EgA7hGxgYAUwBuIccuFgA5jCgBPAA6KY8PrBqKhMACYhFcsCCiVQkWPwVoAFAEpUAPgJiUkoPekZ8ZjYgA
return action;
}
//# sourceMappingURL=core.js.map

View File

@ -1 +1 @@
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../../client/operations/actions/core.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACxE,OAAO,EACL,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,0BAA0B,CAAA;AAEjC,cAAc;AACd,MAAM,UAAU,YAAY,CAC1B,mBAA2B,EAC3B,YAAuB;IAEvB,MAAM,WAAW,GAAG,kBAAkB,CAAC,mBAAmB,CAAC,CAAA;IAE3D,KAAK,UAAU,cAAc,CAAC,IAAI,EAAE,mCAAmC;QACrE,wBAAwB,CAAC,mCAAmC,CAAC,CAAA;QAC7D,IAAI,CAAC;YACH,yEAAyE;YACzE,wEAAwE;YACxE,kCAAkC;YAClC,OAAO,MAAM,aAAa,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA;QAC/C,CAAC;gBAAS,CAAC;YACT,MAAM,kBAAkB,CAAC,YAAY,EAAE,mCAAmC,CAAC,CAAA;QAC7E,CAAC;IACH,CAAC;IAED,0EAA0E;IAC1E,yEAAyE;IACzE,6EAA6E;IAC7E,yEAAyE;IACzE,gBAAgB;IAChB,EAAE;IACF,0EAA0E;IAC1E,8EAA8E;IAC9E,wCAAwC;IACxC,MAAM,MAAM,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;IACjD,MAAM,CAAC,QAAQ,GAAG,cAAc,CAAA;IAEhC,OAAO,MAAkC,CAAA;AAC3C,CAAC"}
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../../client/operations/actions/core.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACxE,OAAO,EACL,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,0BAA0B,CAAA;AAEjC,cAAc;AACd,MAAM,UAAU,YAAY,CAC1B,mBAA2B,EAC3B,YAAuB;IAEvB,MAAM,WAAW,GAAG,kBAAkB,CAAC,mBAAmB,CAAC,CAAA;IAE3D,KAAK,UAAU,cAAc,CAAC,IAAI,EAAE,mCAAmC;QACrE,wBAAwB,CAAC,mCAAmC,CAAC,CAAA;QAC7D,IAAI,CAAC;YACH,yEAAyE;YACzE,wEAAwE;YACxE,kCAAkC;YAClC,OAAO,MAAM,aAAa,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA;QAC/C,CAAC;gBAAS,CAAC;YACT,MAAM,kBAAkB,CAAC,YAAY,EAAE,mCAAmC,CAAC,CAAA;QAC7E,CAAC;IACH,CAAC;IAED,0EAA0E;IAC1E,yEAAyE;IACzE,6EAA6E;IAC7E,yEAAyE;IACzE,gBAAgB;IAChB,EAAE;IACF,0EAA0E;IAC1E,8EAA8E;IAC9E,wCAAwC;IACxC,MAAM,MAAM,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;IACjD,MAAM,CAAC,QAAQ,GAAG,cAAc,CAAA;IAEhC,oDAAoD;IACpD,wEAAwE;IACxE,2BAA2B;IAC3B,2MAA2M;IAC3M,OAAO,MAA6C,CAAA;AACtD,CAAC"}

View File

@ -39,7 +39,10 @@ export function useAction(actionFn, actionOptions) {
// clearly separate our opinionated API from React Query's lower-level
// advanced API (which users can also use)
const mutation = useMutation(mutationFn, options);
return (args) => mutation.mutateAsync(args);
// This assertion is necessary because, when the Input is void, we want to
// present the function as not accepting a payload (which isn't consistent
// with how it's defined).
return ((args) => mutation.mutateAsync(args));
}
/**
* Translates/Desugars a public optimistic update definition object into a
@ -76,10 +79,13 @@ function translateToInternalDefinition(publicOptimisticUpdateDefinition) {
* @returns An decorated action which performs optimistic updates.
*/
function makeOptimisticUpdateMutationFn(actionFn, optimisticUpdateDefinitions) {
return function performActionWithOptimisticUpdates(item) {
return (function performActionWithOptimisticUpdates(item) {
const specificOptimisticUpdateDefinitions = optimisticUpdateDefinitions.map((generalDefinition) => getOptimisticUpdateDefinitionForSpecificItem(generalDefinition, item));
return actionFn.internal(item, specificOptimisticUpdateDefinitions);
};
// This assertion is necessary because, when the Input is void, we want to
// present the function as not accepting a payload (which isn't consistent
// with how it's defined).
});
}
/**
* Given a ReactQuery query client and our internal definition of optimistic

View File

@ -1 +1 @@
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../client/operations/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,WAAW,EAEX,cAAc,EACd,QAAQ,IAAI,UAAU,GAEvB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAErD,aAAa;AACb,MAAM,UAAU,QAAQ,CACtB,KAA2B,EAC3B,WAAmB,EACnB,OAAa;IAEb,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;QAChC,MAAM,IAAI,SAAS,CAAC,6CAA6C,CAAC,CAAA;IACpE,CAAC;IAED,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC;QACzB,MAAM,IAAI,SAAS,CAAC,uDAAuD,CAAC,CAAA;IAC9E,CAAC;IAED,OAAO,UAAU;QACf,2EAA2E;QAC3E,sEAAsE;QACtE,QAAQ,EAAE,iBAAiB,CAAC,KAAK,EAAE,WAAW,CAAC,EAC/C,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,IAC9B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ueryCacheKey(query, payload) {
export function createQuery(relativeQueryPath, entitiesUsed) {
const queryRoute = makeOperationRoute(relativeQueryPath);
const queryCacheKey = [relativeQueryPath];
const queryFn = async (queryArgs) => {
const queryFn = (async (queryArgs) => {
const serverResult = await callOperation(queryRoute, queryArgs);
// todo: The full queryCacheKey is constructed in two places, both here and
// inside the useQuery hook. See
// https://github.com/wasp-lang/wasp/issues/2017
const queryCacheKey = makeQueryCacheKey(queryFn, queryArgs);
return getActiveOptimisticUpdates(queryCacheKey).reduce((result, update) => update(result), serverResult);
};
// This assertion is necessary because, when the Input is void, we want to
// present the function as not accepting a payload (which isn't consistent
// with how it's defined).
});
return buildAndRegisterQuery(queryFn, { queryCacheKey, queryRoute, entitiesUsed });
}
// PRIVATE API (used in SDK)

View File

@ -1 +1 @@
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../../client/operations/queries/core.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACxE,OAAO,EACL,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,uBAAuB,CAAA;AAE9B,gCAAgC;AAChC,6EAA6E;AAC7E,8DAA8D;AAC9D,MAAM,UAAU,iBAAiB,CAC/B,KAA2B,EAC3B,OAAc;IAEd,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC;QAC5B,CAAC,GAAG,KAAK,CAAC,aAAa,EAAE,OAAO,CAAC;QAC/B,CAAC,CAAC,KAAK,CAAC,aAAa,CAAA;AAC3B,CAAC;AAED,6BAA6B;AAC7B,MAAM,UAAU,WAAW,CACzB,iBAAyB,EACzB,YAAsB;IAEtB,MAAM,UAAU,GAAG,kBAAkB,CAAC,iBAAiB,CAAC,CAAA;IACxD,MAAM,aAAa,GAAG,CAAC,iBAAiB,CAAC,CAAA;IAEzC,MAAM,OAAO,GAAmC,KAAK,EAAE,SAAS,EAAE,EAAE;QAClE,MAAM,YAAY,GAAG,MAAM,aAAa,CAAC,UAAU,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yB,EACzB,YAAsB;IAEtB,MAAM,UAAU,GAAG,kBAAkB,CAAC,iBAAiB,CAAC,CAAA;IACxD,MAAM,aAAa,GAAG,CAAC,iBAAiB,CAAC,CAAA;IAEzC,MAAM,OAAO,GAAG,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;QACnC,MAAM,YAAY,GAAG,MAAM,aAAa,CAAC,UAAU,EAAE,SAAS,CAAC,CAAA;QAC/D,2EAA2E;QAC3E,gCAAgC;QAChC,gDAAgD;QAChD,MAAM,aAAa,GAAG,iBAAiB,CAAC,OAAiC,EAAE,SAAS,CAAC,CAAA;QACrF,OAAO,0BAA0B,CAAC,aAAa,CAAC,CAAC,MAAM,CACrD,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAClC,YAAY,CACb,CAAA;QACD,0EAA0E;QAC1E,0EAA0E;QAC1E,0BAA0B;IAC5B,CAAC,CAAmC,CAAA;IAEpC,OAAO,qBAAqB,CAC1B,OAAO,EACP,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,CAC5C,CAAA;AACH,CAAC;AAED,4BAA4B;AAC5B,MAAM,UAAU,qBAAqB,CACnC,OAAW,EACX,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAC+B;IAExE,MAAM,KAAK,GAAG,OAA+B,CAAA;IAE7C,KAAK,CAAC,aAAa,GAAG,aAAa,CAAA;IACnC,KAAK,CAAC,KAAK,GAAG,UAAU,CAAA;IACxB,uBAAuB,CAAC,KAAK,CAAC,aAAa,EAAE,YAAY,CAAC,CAAA;IAE1D,OAAO,KAAK,CAAA;AACd,CAAC"}

View File

@ -34,5 +34,5 @@ export type GenericBackendOperation = (args: never, context: any) => unknown;
* A supertype of all possible frontend RPC function types.
*/
export type GenericOperationRpc = (args: never) => Promise<unknown>;
type ClientOperation<Input, Output> = [Input] extends [never] ? (args?: unknown) => Promise<Output> : (args: Input) => Promise<Output>;
type ClientOperation<Input, Output> = [Input] extends [never] ? (args?: unknown) => Promise<Output> : [Input] extends [void] ? () => Promise<Output> : (args: Input) => Promise<Output>;
export {};

View File

@ -1,15 +1,15 @@
import { type Expand } from 'wasp/universal/types';
import { type Request, type Response } from 'express';
import { type ParamsDictionary as ExpressParams, type Query as ExpressQuery } from 'express-serve-static-core';
import { type _Entity } from "./taggedEntities";
import { type Payload } from "./serialization";
import { type _Entity } from './taggedEntities';
import { type Payload } from './serialization';
export * from "./taggedEntities";
export * from "./serialization";
export type Query<Entities extends _Entity[], Input extends Payload, Output extends Payload> = Operation<Entities, Input, Output>;
export type Action<Entities extends _Entity[], Input extends Payload, Output extends Payload> = Operation<Entities, Input, Output>;
type Operation<Entities extends _Entity[], Input, Output> = (args: Input, context: Context<Entities>) => Output | Promise<Output>;
export type UnauthenticatedQueryDefinition<Entities extends _Entity[], Input extends Payload, Output extends Payload> = UnauthenticatedOperationDefinition<Entities, Input, Output>;
export type UnauthenticatedActionDefinition<Entities extends _Entity[], Input extends Payload, Output extends Payload> = UnauthenticatedOperationDefinition<Entities, Input, Output>;
export type UnauthenticatedOperationDefinition<Entities extends _Entity[], Input extends Payload, Output extends Payload> = (args: Input, context: Context<Entities>) => Output | Promise<Output>;
export type Api<Entities extends _Entity[], Params extends ExpressParams, ResBody, ReqBody, ReqQuery extends ExpressQuery, Locals extends Record<string, any>> = (req: Request<Params, ResBody, ReqBody, ReqQuery, Locals>, res: Response<ResBody, Locals>, context: Context<Entities>) => void;
type EntityMap<Entities extends _Entity[]> = {
export type EntityMap<Entities extends _Entity[]> = {
[EntityName in Entities[number]["_entityName"]]: PrismaDelegate[EntityName];
};
export type PrismaDelegate = {};

View File

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/_types/index.ts"],"names":[],"mappings":"AAOA,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA"}
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/_types/index.ts"],"names":[],"mappings":"AAUA,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA"}

View File

@ -0,0 +1,42 @@
import { _Awaited, _ReturnType } from '../../universal/types';
import { _Entity, UnauthenticatedOperationDefinition, Payload } from '../_types';
/**
* Constructs the unauthenticated operation's server-side API type from its
* definition.
*
* @template OperationDefinition The type of the unauthenticated operation's
* definition.
*/
export type UnauthenticatedOperationFor<OperationDefinition extends GenericUnauthenticatedOperationDefinition> = Parameters<OperationDefinition> extends [] ? UnauthenticatedOperation<void, _Awaited<_ReturnType<OperationDefinition>>> : UnauthenticatedOperation<Parameters<OperationDefinition>[0], _Awaited<_ReturnType<OperationDefinition>>>;
/**
* Creates the server-side API for an unauthenticated operation.
*
* @template OperationDefinition The type of the unauthenticated operation's definition.
* @param userOperation The unauthenticated operation's definition.
* @param entities The unauthenticated operation's entity map .
* @returns The server-side API for the provided unauthenticated operation.
*/
export declare function createUnauthenticatedOperation<OperationDefinition extends GenericUnauthenticatedOperationDefinition>(userOperation: OperationDefinition, entities: EntityMapFor<OperationDefinition>): UnauthenticatedOperationFor<OperationDefinition>;
/**
* Constructs the type for an unauthenticated operation's server-side API.
*
* @template Input The type of the payload the operation expects (must be
* `void` if the operation doesn't expect a payload).
* @template Output The type of the operation's return value.
*/
type UnauthenticatedOperation<Input, Output> = [
Input
] extends [never] ? (args: unknown) => Promise<Output> : [Input] extends [void] ? () => Promise<Output> : (args: Input) => Promise<Output>;
/**
* The principal type for an unauthenticated operation's definition (i.e., all
* unauthenticated operation definition types are a subtype of this type).
*
*/
type GenericUnauthenticatedOperationDefinition = UnauthenticatedOperationDefinition<_Entity[], never, Payload>;
/**
* Queries the entity map from the type of the operation's definition.
*
* @template OperationDefinition The type of the operation's definition.
*/
type EntityMapFor<OperationDefinition extends GenericUnauthenticatedOperationDefinition> = Parameters<OperationDefinition>[1]["entities"];
export {};

View File

@ -0,0 +1,21 @@
// PRIVATE API (used in SDK)
/**
* Creates the server-side API for an unauthenticated operation.
*
* @template OperationDefinition The type of the unauthenticated operation's definition.
* @param userOperation The unauthenticated operation's definition.
* @param entities The unauthenticated operation's entity map .
* @returns The server-side API for the provided unauthenticated operation.
*/
export function createUnauthenticatedOperation(userOperation, entities) {
async function operation(payload) {
return userOperation(payload, {
entities,
});
}
// This assertion is necessary because, when the Input is void, we want to present
// the function as not accepting a payload (which isn't consistent with how
// it's defined).
return operation;
}
//# sourceMappingURL=wrappers.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"wrappers.js","sourceRoot":"","sources":["../../../server/operations/wrappers.ts"],"names":[],"mappings":"AA8BA,4BAA4B;AAC5B;;;;;;;GAOG;AACH,MAAM,UAAU,8BAA8B,CAG5C,aAAkC,EAClC,QAA2C;IAE3C,KAAK,UAAU,SAAS,CAAC,OAA2C;QAClE,OAAO,aAAa,CAAC,OAAO,EAAE;YAC5B,QAAQ;SACT,CAAC,CAAA;IACJ,CAAC;IACD,kFAAkF;IAClF,2EAA2E;IAC3E,iBAAiB;IACjB,OAAO,SAA6D,CAAA;AACtE,CAAC"}

View File

@ -1,23 +1,33 @@
import { type Expand } from 'wasp/universal/types';
import { type Expand } from 'wasp/universal/types'
import { type Request, type Response } from 'express'
import { type ParamsDictionary as ExpressParams, type Query as ExpressQuery } from 'express-serve-static-core'
import {
type ParamsDictionary as ExpressParams,
type Query as ExpressQuery,
} from 'express-serve-static-core'
import { prisma } from 'wasp/server'
import { type _Entity } from "./taggedEntities"
import { type Payload } from "./serialization";
import { type _Entity } from './taggedEntities'
import { type Payload } from './serialization'
export * from "./taggedEntities"
export * from "./serialization"
export type Query<Entities extends _Entity[], Input extends Payload, Output extends Payload> =
Operation<Entities, Input, Output>
export type UnauthenticatedQueryDefinition<
Entities extends _Entity[],
Input extends Payload,
Output extends Payload
> = UnauthenticatedOperationDefinition<Entities, Input, Output>
export type Action<Entities extends _Entity[], Input extends Payload, Output extends Payload> =
Operation<Entities, Input, Output>
export type UnauthenticatedActionDefinition<
Entities extends _Entity[],
Input extends Payload,
Output extends Payload
> = UnauthenticatedOperationDefinition<Entities, Input, Output>
type Operation<Entities extends _Entity[], Input, Output> = (
args: Input,
context: Context<Entities>,
) => Output | Promise<Output>
export type UnauthenticatedOperationDefinition<
Entities extends _Entity[],
Input extends Payload,
Output extends Payload
> = (args: Input, context: Context<Entities>) => Output | Promise<Output>
export type Api<
Entities extends _Entity[],
@ -32,7 +42,7 @@ export type Api<
context: Context<Entities>,
) => void
type EntityMap<Entities extends _Entity[]> = {
export type EntityMap<Entities extends _Entity[]> = {
[EntityName in Entities[number]["_entityName"]]: PrismaDelegate[EntityName]
}

View File

@ -1,2 +1,6 @@
import { prisma } from 'wasp/server'
import { prisma } from 'wasp/server'
import {
type UnauthenticatedOperationFor,
createUnauthenticatedOperation,
} from '../wrappers.js'

View File

@ -1,2 +1,6 @@
import { prisma } from 'wasp/server'
import { prisma } from 'wasp/server'
import {
type UnauthenticatedOperationFor,
createUnauthenticatedOperation,
} from '../wrappers.js'

View File

@ -0,0 +1,90 @@
import { _Awaited, _ReturnType } from '../../universal/types'
import {
_Entity,
UnauthenticatedOperationDefinition,
Payload,
} from '../_types'
// PRIVATE API (used in SDK)
// Explanation:
// - Custom `_Awaited` and `_ReturnType` - Read the comments above their
// definitions.
// - `Parameters<OperationDefinition> extends []` - Same reason as described here:
// https://github.com/wasp-lang/wasp/pull/1992/files#r1583040080
/**
* Constructs the unauthenticated operation's server-side API type from its
* definition.
*
* @template OperationDefinition The type of the unauthenticated operation's
* definition.
*/
export type UnauthenticatedOperationFor<
OperationDefinition extends GenericUnauthenticatedOperationDefinition
> = Parameters<OperationDefinition> extends []
? UnauthenticatedOperation<void, _Awaited<_ReturnType<OperationDefinition>>>
: UnauthenticatedOperation<
Parameters<OperationDefinition>[0],
_Awaited<_ReturnType<OperationDefinition>>
>
// PRIVATE API (used in SDK)
/**
* Creates the server-side API for an unauthenticated operation.
*
* @template OperationDefinition The type of the unauthenticated operation's definition.
* @param userOperation The unauthenticated operation's definition.
* @param entities The unauthenticated operation's entity map .
* @returns The server-side API for the provided unauthenticated operation.
*/
export function createUnauthenticatedOperation<
OperationDefinition extends GenericUnauthenticatedOperationDefinition
>(
userOperation: OperationDefinition,
entities: EntityMapFor<OperationDefinition>
): UnauthenticatedOperationFor<OperationDefinition> {
async function operation(payload: Parameters<OperationDefinition>[0]) {
return userOperation(payload, {
entities,
})
}
// This assertion is necessary because, when the Input is void, we want to present
// the function as not accepting a payload (which isn't consistent with how
// it's defined).
return operation as UnauthenticatedOperationFor<OperationDefinition>
}
/**
* Constructs the type for an unauthenticated operation's server-side API.
*
* @template Input The type of the payload the operation expects (must be
* `void` if the operation doesn't expect a payload).
* @template Output The type of the operation's return value.
*/
type UnauthenticatedOperation<Input, Output> =
[Input] extends [never]
? (args: unknown) => Promise<Output>
: [Input] extends [void]
? () => Promise<Output>
: (args: Input) => Promise<Output>
/**
* The principal type for an unauthenticated operation's definition (i.e., all
* unauthenticated operation definition types are a subtype of this type).
*
*/
type GenericUnauthenticatedOperationDefinition = UnauthenticatedOperationDefinition<
// NOTE(filip): Not quite sure I understand what's going on with Variance here.
_Entity[],
never,
Payload
>
/**
* Queries the entity map from the type of the operation's definition.
*
* @template OperationDefinition The type of the operation's definition.
*/
type EntityMapFor<OperationDefinition extends GenericUnauthenticatedOperationDefinition> =
Parameters<OperationDefinition>[1]["entities"]

View File

@ -37,7 +37,11 @@ export function createAction<BackendAction extends GenericBackendOperation>(
const action = (args) => internalAction(args, [])
action.internal = internalAction
return action as ActionFor<BackendAction>
// NOTE: I'm not sure why unknown is necessary here,
// it might have something to do with functions allowing evolving types,
// // while objects to not:
// https://www.typescriptlang.org/play/?#code/MYewdgzgLgBCBGArGBeGBvGBDAXDA5AGYgj4wC+AUAogHTyoHxYBO+llA9JzIQK5hgUAJbhsAG3EgA7hGxgYAUwBuIccuFgA5jCgBPAA6KY8PrBqKhMACYhFcsCCiVQkWPwVoAFAEpUAPgJiUkoPekZ8ZjYgA
return action as unknown as ActionFor<BackendAction>
}
// PRIVATE API

View File

@ -72,7 +72,11 @@ export function useAction<Input = unknown, Output = unknown>(
// clearly separate our opinionated API from React Query's lower-level
// advanced API (which users can also use)
const mutation = useMutation(mutationFn, options);
return (args) => mutation.mutateAsync(args);
// This assertion is necessary because, when the Input is void, we want to
// present the function as not accepting a payload (which isn't consistent
// with how it's defined).
return ((args: Input) => mutation.mutateAsync(args)) as typeof actionFn;
}
// PUBLIC API
@ -200,7 +204,7 @@ function makeOptimisticUpdateMutationFn<Input, Output, CachedData>(
CachedData
>[]
): typeof actionFn {
return function performActionWithOptimisticUpdates(item) {
return (function performActionWithOptimisticUpdates(item?: Input) {
const specificOptimisticUpdateDefinitions = optimisticUpdateDefinitions.map(
(generalDefinition) =>
getOptimisticUpdateDefinitionForSpecificItem(generalDefinition, item)
@ -209,7 +213,10 @@ function makeOptimisticUpdateMutationFn<Input, Output, CachedData>(
item,
specificOptimisticUpdateDefinitions
);
};
// This assertion is necessary because, when the Input is void, we want to
// present the function as not accepting a payload (which isn't consistent
// with how it's defined).
}) as typeof actionFn;
}
/**

View File

@ -1,6 +1,6 @@
import { Route } from 'wasp/client'
import type { _Awaited, _ReturnType } from 'wasp/universal/types'
import type {
import type {
GenericBackendOperation,
GenericOperationRpc,
OperationRpcFor,
@ -20,9 +20,9 @@ export function makeQueryCacheKey<Input, Output>(
query: Query<Input, Output>,
payload: Input
): (string | Input)[] {
return payload !== undefined ?
[...query.queryCacheKey, payload]
: query.queryCacheKey
return payload !== undefined ?
[...query.queryCacheKey, payload]
: query.queryCacheKey
}
// PRIVATE API (unsed in SDK)
@ -33,7 +33,7 @@ export function createQuery<BackendQuery extends GenericBackendOperation>(
const queryRoute = makeOperationRoute(relativeQueryPath)
const queryCacheKey = [relativeQueryPath]
const queryFn: QueryFunctionFor<BackendQuery> = async (queryArgs) => {
const queryFn = (async (queryArgs) => {
const serverResult = await callOperation(queryRoute, queryArgs)
// todo: The full queryCacheKey is constructed in two places, both here and
// inside the useQuery hook. See
@ -43,7 +43,10 @@ export function createQuery<BackendQuery extends GenericBackendOperation>(
(result, update) => update(result),
serverResult,
)
}
// This assertion is necessary because, when the Input is void, we want to
// present the function as not accepting a payload (which isn't consistent
// with how it's defined).
}) as QueryFunctionFor<BackendQuery>
return buildAndRegisterQuery(
queryFn,
@ -54,12 +57,12 @@ export function createQuery<BackendQuery extends GenericBackendOperation>(
// PRIVATE API (used in SDK)
export function buildAndRegisterQuery<QF extends GenericOperationRpc>(
queryFn: QF,
{ queryCacheKey, queryRoute, entitiesUsed }:
{ queryCacheKey: string[], queryRoute: Route, entitiesUsed: string[] }
{ queryCacheKey, queryRoute, entitiesUsed }:
{ queryCacheKey: string[], queryRoute: Route, entitiesUsed: string[] }
): QueryForFunction<QF> {
const query = queryFn as QueryForFunction<QF>
query.queryCacheKey = queryCacheKey
query.queryCacheKey = queryCacheKey
query.route = queryRoute
addResourcesUsedByQuery(query.queryCacheKey, entitiesUsed)
@ -77,7 +80,7 @@ export type QueryFor<BackendQuery extends GenericBackendOperation> =
/**
* Constructs the client Query function type from the type of the Query's
* definition on the backend.
*/
*/
type QueryFunctionFor<BackendQuery extends GenericBackendOperation> =
OperationRpcFor<BackendQuery>

View File

@ -77,4 +77,6 @@ export type GenericOperationRpc = (args: never) => Promise<unknown>
// Read this to understand the type: https://github.com/wasp-lang/wasp/pull/1090#discussion_r1159732471
type ClientOperation<Input, Output> = [Input] extends [never]
? (args?: unknown) => Promise<Output>
: (args: Input) => Promise<Output>;
: [Input] extends [void]
? () => Promise<Output>
: (args: Input) => Promise<Output>

View File

@ -26,6 +26,10 @@ export function createAction(relativeActionRoute, entitiesUsed) {
// we can always hide it using a Symbol.
const action = (args) => internalAction(args, []);
action.internal = internalAction;
// NOTE: I'm not sure why unknown is necessary here,
// it might have something to do with functions allowing evolving types,
// // while objects to not:
// https://www.typescriptlang.org/play/?#code/MYewdgzgLgBCBGArGBeGBvGBDAXDA5AGYgj4wC+AUAogHTyoHxYBO+llA9JzIQK5hgUAJbhsAG3EgA7hGxgYAUwBuIccuFgA5jCgBPAA6KY8PrBqKhMACYhFcsCCiVQkWPwVoAFAEpUAPgJiUkoPekZ8ZjYgA
return action;
}
//# sourceMappingURL=core.js.map

View File

@ -1 +1 @@
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../../client/operations/actions/core.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACxE,OAAO,EACL,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,0BAA0B,CAAA;AAEjC,cAAc;AACd,MAAM,UAAU,YAAY,CAC1B,mBAA2B,EAC3B,YAAuB;IAEvB,MAAM,WAAW,GAAG,kBAAkB,CAAC,mBAAmB,CAAC,CAAA;IAE3D,KAAK,UAAU,cAAc,CAAC,IAAI,EAAE,mCAAmC;QACrE,wBAAwB,CAAC,mCAAmC,CAAC,CAAA;QAC7D,IAAI,CAAC;YACH,yEAAyE;YACzE,wEAAwE;YACxE,kCAAkC;YAClC,OAAO,MAAM,aAAa,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA;QAC/C,CAAC;gBAAS,CAAC;YACT,MAAM,kBAAkB,CAAC,YAAY,EAAE,mCAAmC,CAAC,CAAA;QAC7E,CAAC;IACH,CAAC;IAED,0EAA0E;IAC1E,yEAAyE;IACzE,6EAA6E;IAC7E,yEAAyE;IACzE,gBAAgB;IAChB,EAAE;IACF,0EAA0E;IAC1E,8EAA8E;IAC9E,wCAAwC;IACxC,MAAM,MAAM,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;IACjD,MAAM,CAAC,QAAQ,GAAG,cAAc,CAAA;IAEhC,OAAO,MAAkC,CAAA;AAC3C,CAAC"}
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../../client/operations/actions/core.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACxE,OAAO,EACL,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,0BAA0B,CAAA;AAEjC,cAAc;AACd,MAAM,UAAU,YAAY,CAC1B,mBAA2B,EAC3B,YAAuB;IAEvB,MAAM,WAAW,GAAG,kBAAkB,CAAC,mBAAmB,CAAC,CAAA;IAE3D,KAAK,UAAU,cAAc,CAAC,IAAI,EAAE,mCAAmC;QACrE,wBAAwB,CAAC,mCAAmC,CAAC,CAAA;QAC7D,IAAI,CAAC;YACH,yEAAyE;YACzE,wEAAwE;YACxE,kCAAkC;YAClC,OAAO,MAAM,aAAa,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA;QAC/C,CAAC;gBAAS,CAAC;YACT,MAAM,kBAAkB,CAAC,YAAY,EAAE,mCAAmC,CAAC,CAAA;QAC7E,CAAC;IACH,CAAC;IAED,0EAA0E;IAC1E,yEAAyE;IACzE,6EAA6E;IAC7E,yEAAyE;IACzE,gBAAgB;IAChB,EAAE;IACF,0EAA0E;IAC1E,8EAA8E;IAC9E,wCAAwC;IACxC,MAAM,MAAM,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;IACjD,MAAM,CAAC,QAAQ,GAAG,cAAc,CAAA;IAEhC,oDAAoD;IACpD,wEAAwE;IACxE,2BAA2B;IAC3B,2MAA2M;IAC3M,OAAO,MAA6C,CAAA;AACtD,CAAC"}

View File

@ -39,7 +39,10 @@ export function useAction(actionFn, actionOptions) {
// clearly separate our opinionated API from React Query's lower-level
// advanced API (which users can also use)
const mutation = useMutation(mutationFn, options);
return (args) => mutation.mutateAsync(args);
// This assertion is necessary because, when the Input is void, we want to
// present the function as not accepting a payload (which isn't consistent
// with how it's defined).
return ((args) => mutation.mutateAsync(args));
}
/**
* Translates/Desugars a public optimistic update definition object into a
@ -76,10 +79,13 @@ function translateToInternalDefinition(publicOptimisticUpdateDefinition) {
* @returns An decorated action which performs optimistic updates.
*/
function makeOptimisticUpdateMutationFn(actionFn, optimisticUpdateDefinitions) {
return function performActionWithOptimisticUpdates(item) {
return (function performActionWithOptimisticUpdates(item) {
const specificOptimisticUpdateDefinitions = optimisticUpdateDefinitions.map((generalDefinition) => getOptimisticUpdateDefinitionForSpecificItem(generalDefinition, item));
return actionFn.internal(item, specificOptimisticUpdateDefinitions);
};
// This assertion is necessary because, when the Input is void, we want to
// present the function as not accepting a payload (which isn't consistent
// with how it's defined).
});
}
/**
* Given a ReactQuery query client and our internal definition of optimistic

View File

@ -1 +1 @@
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../client/operations/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,WAAW,EAEX,cAAc,EACd,QAAQ,IAAI,UAAU,GAEvB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAErD,aAAa;AACb,MAAM,UAAU,QAAQ,CACtB,KAA2B,EAC3B,WAAmB,EACnB,OAAa;IAEb,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;QAChC,MAAM,IAAI,SAAS,CAAC,6CAA6C,CAAC,CAAA;IACpE,CAAC;IAED,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC;QACzB,MAAM,IAAI,SAAS,CAAC,uDAAuD,CAAC,CAAA;IAC9E,CAAC;IAED,OAAO,UAAU;QACf,2EAA2E;QAC3E,sEAAsE;QACtE,QAAQ,EAAE,iBAAiB,CAAC,KAAK,EAAE,WAAW,CAAC,EAC/C,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,IAC9B,OAAO,EACV,CAAA;AACJ,CAAC;AAED,aAAa;AACb;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CACvB,QAA+B,EAC/B,aAAoC;IAEpC,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IAErC,IAAI,UAAU,GAAG,QAAQ,CAAC;IAC1B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AAC;QAEH,OAAO,EAAE,YAAY,EAAE,CAAC;IAC1B,CAAC;IAED,SAAS,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO;QACnC,+EAA+E;QAC/E,8EAA8E;QAC9E,8EAA8E;QAC9E,+EAA+E;QAC/E,YAAY;QACZ,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;YACpD,MAAM,WAAW,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;YAC1C,WAAW,CAAC,YAAY,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO;QACL,QAAQ;QACR,OAAO;KACR,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAS,4CAA4C,CACnD,0BAGC,EACD,IAAiB;IAEjB,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,0BAA0B,CAAC;IAChE,OAAO;QACL,QAAQ,EAAE,WAAW,CAAC,IAAI,CAAC;QAC3B,WAAW,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,CAAC;KAC7C,CAAC;AACJ,CAAC;AAED,qEAAqE;AACrE,+EAA+E;AAC/E;;;;;;GAMG;AACH,SAAS,0BAA0B,CACjC,cAAgD;IAEhD,MAAM,CAAC,OAAO,EAAE,GAAG,SAAS,CAAC,GAAG,cAAc,CAAC;IAC/C,OAAO,CAAC,GAAI,OAAe,CAAC,aAAa,EAAE,GAAG,SAAS,CAAC,CAAC;AAC3D,CAAC"}

View File

@ -12,14 +12,17 @@ export function makeQueryCacheKey(query, payload) {
export function createQuery(relativeQueryPath, entitiesUsed) {
const queryRoute = makeOperationRoute(relativeQueryPath);
const queryCacheKey = [relativeQueryPath];
const queryFn = async (queryArgs) => {
const queryFn = (async (queryArgs) => {
const serverResult = await callOperation(queryRoute, queryArgs);
// todo: The full queryCacheKey is constructed in two places, both here and
// inside the useQuery hook. See
// https://github.com/wasp-lang/wasp/issues/2017
const queryCacheKey = makeQueryCacheKey(queryFn, queryArgs);
return getActiveOptimisticUpdates(queryCacheKey).reduce((result, update) => update(result), serverResult);
};
// This assertion is necessary because, when the Input is void, we want to
// present the function as not accepting a payload (which isn't consistent
// with how it's defined).
});
return buildAndRegisterQuery(queryFn, { queryCacheKey, queryRoute, entitiesUsed });
}
// PRIVATE API (used in SDK)

View File

@ -1 +1 @@
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../../client/operations/queries/core.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACxE,OAAO,EACL,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,uBAAuB,CAAA;AAE9B,gCAAgC;AAChC,6EAA6E;AAC7E,8DAA8D;AAC9D,MAAM,UAAU,iBAAiB,CAC/B,KAA2B,EAC3B,OAAc;IAEd,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC;QAC5B,CAAC,GAAG,KAAK,CAAC,aAAa,EAAE,OAAO,CAAC;QAC/B,CAAC,CAAC,KAAK,CAAC,aAAa,CAAA;AAC3B,CAAC;AAED,6BAA6B;AAC7B,MAAM,UAAU,WAAW,CACzB,iBAAyB,EACzB,YAAsB;IAEtB,MAAM,UAAU,GAAG,kBAAkB,CAAC,iBAAiB,CAAC,CAAA;IACxD,MAAM,aAAa,GAAG,CAAC,iBAAiB,CAAC,CAAA;IAEzC,MAAM,OAAO,GAAmC,KAAK,EAAE,SAAS,EAAE,EAAE;QAClE,MAAM,YAAY,GAAG,MAAM,aAAa,CAAC,UAAU,EAAE,SAAS,CAAC,CAAA;QAC/D,2EAA2E;QAC3E,gCAAgC;QAChC,gDAAgD;QAChD,MAAM,aAAa,GAAG,iBAAiB,CAAC,OAAiC,EAAE,SAAS,CAAC,CAAA;QACrF,OAAO,0BAA0B,CAAC,aAAa,CAAC,CAAC,MAAM,CACrD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MAAM,YAAY,GAAG,MAAM,aAAa,CAAC,UAAU,EAAE,SAAS,CAAC,CAAA;QAC/D,2EAA2E;QAC3E,gCAAgC;QAChC,gDAAgD;QAChD,MAAM,aAAa,GAAG,iBAAiB,CAAC,OAAiC,EAAE,SAAS,CAAC,CAAA;QACrF,OAAO,0BAA0B,CAAC,aAAa,CAAC,CAAC,MAAM,CACrD,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAClC,YAAY,CACb,CAAA;QACD,0EAA0E;QAC1E,0EAA0E;QAC1E,0BAA0B;IAC5B,CAAC,CAAmC,CAAA;IAEpC,OAAO,qBAAqB,CAC1B,OAAO,EACP,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,CAC5C,CAAA;AACH,CAAC;AAED,4BAA4B;AAC5B,MAAM,UAAU,qBAAqB,CACnC,OAAW,EACX,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAC+B;IAExE,MAAM,KAAK,GAAG,OAA+B,CAAA;IAE7C,KAAK,CAAC,aAAa,GAAG,aAAa,CAAA;IACnC,KAAK,CAAC,KAAK,GAAG,UAAU,CAAA;IACxB,uBAAuB,CAAC,KAAK,CAAC,aAAa,EAAE,YAAY,CAAC,CAAA;IAE1D,OAAO,KAAK,CAAA;AACd,CAAC"}

View File

@ -34,5 +34,5 @@ export type GenericBackendOperation = (args: never, context: any) => unknown;
* A supertype of all possible frontend RPC function types.
*/
export type GenericOperationRpc = (args: never) => Promise<unknown>;
type ClientOperation<Input, Output> = [Input] extends [never] ? (args?: unknown) => Promise<Output> : (args: Input) => Promise<Output>;
type ClientOperation<Input, Output> = [Input] extends [never] ? (args?: unknown) => Promise<Output> : [Input] extends [void] ? () => Promise<Output> : (args: Input) => Promise<Output>;
export {};

View File

@ -1,15 +1,15 @@
import { type Expand } from 'wasp/universal/types';
import { type Request, type Response } from 'express';
import { type ParamsDictionary as ExpressParams, type Query as ExpressQuery } from 'express-serve-static-core';
import { type _Entity } from "./taggedEntities";
import { type Payload } from "./serialization";
import { type _Entity } from './taggedEntities';
import { type Payload } from './serialization';
export * from "./taggedEntities";
export * from "./serialization";
export type Query<Entities extends _Entity[], Input extends Payload, Output extends Payload> = Operation<Entities, Input, Output>;
export type Action<Entities extends _Entity[], Input extends Payload, Output extends Payload> = Operation<Entities, Input, Output>;
type Operation<Entities extends _Entity[], Input, Output> = (args: Input, context: Context<Entities>) => Output | Promise<Output>;
export type UnauthenticatedQueryDefinition<Entities extends _Entity[], Input extends Payload, Output extends Payload> = UnauthenticatedOperationDefinition<Entities, Input, Output>;
export type UnauthenticatedActionDefinition<Entities extends _Entity[], Input extends Payload, Output extends Payload> = UnauthenticatedOperationDefinition<Entities, Input, Output>;
export type UnauthenticatedOperationDefinition<Entities extends _Entity[], Input extends Payload, Output extends Payload> = (args: Input, context: Context<Entities>) => Output | Promise<Output>;
export type Api<Entities extends _Entity[], Params extends ExpressParams, ResBody, ReqBody, ReqQuery extends ExpressQuery, Locals extends Record<string, any>> = (req: Request<Params, ResBody, ReqBody, ReqQuery, Locals>, res: Response<ResBody, Locals>, context: Context<Entities>) => void;
type EntityMap<Entities extends _Entity[]> = {
export type EntityMap<Entities extends _Entity[]> = {
[EntityName in Entities[number]["_entityName"]]: PrismaDelegate[EntityName];
};
export type PrismaDelegate = {};

View File

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/_types/index.ts"],"names":[],"mappings":"AAOA,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA"}
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/_types/index.ts"],"names":[],"mappings":"AAUA,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA"}

View File

@ -0,0 +1,42 @@
import { _Awaited, _ReturnType } from '../../universal/types';
import { _Entity, UnauthenticatedOperationDefinition, Payload } from '../_types';
/**
* Constructs the unauthenticated operation's server-side API type from its
* definition.
*
* @template OperationDefinition The type of the unauthenticated operation's
* definition.
*/
export type UnauthenticatedOperationFor<OperationDefinition extends GenericUnauthenticatedOperationDefinition> = Parameters<OperationDefinition> extends [] ? UnauthenticatedOperation<void, _Awaited<_ReturnType<OperationDefinition>>> : UnauthenticatedOperation<Parameters<OperationDefinition>[0], _Awaited<_ReturnType<OperationDefinition>>>;
/**
* Creates the server-side API for an unauthenticated operation.
*
* @template OperationDefinition The type of the unauthenticated operation's definition.
* @param userOperation The unauthenticated operation's definition.
* @param entities The unauthenticated operation's entity map .
* @returns The server-side API for the provided unauthenticated operation.
*/
export declare function createUnauthenticatedOperation<OperationDefinition extends GenericUnauthenticatedOperationDefinition>(userOperation: OperationDefinition, entities: EntityMapFor<OperationDefinition>): UnauthenticatedOperationFor<OperationDefinition>;
/**
* Constructs the type for an unauthenticated operation's server-side API.
*
* @template Input The type of the payload the operation expects (must be
* `void` if the operation doesn't expect a payload).
* @template Output The type of the operation's return value.
*/
type UnauthenticatedOperation<Input, Output> = [
Input
] extends [never] ? (args: unknown) => Promise<Output> : [Input] extends [void] ? () => Promise<Output> : (args: Input) => Promise<Output>;
/**
* The principal type for an unauthenticated operation's definition (i.e., all
* unauthenticated operation definition types are a subtype of this type).
*
*/
type GenericUnauthenticatedOperationDefinition = UnauthenticatedOperationDefinition<_Entity[], never, Payload>;
/**
* Queries the entity map from the type of the operation's definition.
*
* @template OperationDefinition The type of the operation's definition.
*/
type EntityMapFor<OperationDefinition extends GenericUnauthenticatedOperationDefinition> = Parameters<OperationDefinition>[1]["entities"];
export {};

View File

@ -0,0 +1,21 @@
// PRIVATE API (used in SDK)
/**
* Creates the server-side API for an unauthenticated operation.
*
* @template OperationDefinition The type of the unauthenticated operation's definition.
* @param userOperation The unauthenticated operation's definition.
* @param entities The unauthenticated operation's entity map .
* @returns The server-side API for the provided unauthenticated operation.
*/
export function createUnauthenticatedOperation(userOperation, entities) {
async function operation(payload) {
return userOperation(payload, {
entities,
});
}
// This assertion is necessary because, when the Input is void, we want to present
// the function as not accepting a payload (which isn't consistent with how
// it's defined).
return operation;
}
//# sourceMappingURL=wrappers.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"wrappers.js","sourceRoot":"","sources":["../../../server/operations/wrappers.ts"],"names":[],"mappings":"AA8BA,4BAA4B;AAC5B;;;;;;;GAOG;AACH,MAAM,UAAU,8BAA8B,CAG5C,aAAkC,EAClC,QAA2C;IAE3C,KAAK,UAAU,SAAS,CAAC,OAA2C;QAClE,OAAO,aAAa,CAAC,OAAO,EAAE;YAC5B,QAAQ;SACT,CAAC,CAAA;IACJ,CAAC;IACD,kFAAkF;IAClF,2EAA2E;IAC3E,iBAAiB;IACjB,OAAO,SAA6D,CAAA;AACtE,CAAC"}

View File

@ -1,23 +1,33 @@
import { type Expand } from 'wasp/universal/types';
import { type Expand } from 'wasp/universal/types'
import { type Request, type Response } from 'express'
import { type ParamsDictionary as ExpressParams, type Query as ExpressQuery } from 'express-serve-static-core'
import {
type ParamsDictionary as ExpressParams,
type Query as ExpressQuery,
} from 'express-serve-static-core'
import { prisma } from 'wasp/server'
import { type _Entity } from "./taggedEntities"
import { type Payload } from "./serialization";
import { type _Entity } from './taggedEntities'
import { type Payload } from './serialization'
export * from "./taggedEntities"
export * from "./serialization"
export type Query<Entities extends _Entity[], Input extends Payload, Output extends Payload> =
Operation<Entities, Input, Output>
export type UnauthenticatedQueryDefinition<
Entities extends _Entity[],
Input extends Payload,
Output extends Payload
> = UnauthenticatedOperationDefinition<Entities, Input, Output>
export type Action<Entities extends _Entity[], Input extends Payload, Output extends Payload> =
Operation<Entities, Input, Output>
export type UnauthenticatedActionDefinition<
Entities extends _Entity[],
Input extends Payload,
Output extends Payload
> = UnauthenticatedOperationDefinition<Entities, Input, Output>
type Operation<Entities extends _Entity[], Input, Output> = (
args: Input,
context: Context<Entities>,
) => Output | Promise<Output>
export type UnauthenticatedOperationDefinition<
Entities extends _Entity[],
Input extends Payload,
Output extends Payload
> = (args: Input, context: Context<Entities>) => Output | Promise<Output>
export type Api<
Entities extends _Entity[],
@ -32,7 +42,7 @@ export type Api<
context: Context<Entities>,
) => void
type EntityMap<Entities extends _Entity[]> = {
export type EntityMap<Entities extends _Entity[]> = {
[EntityName in Entities[number]["_entityName"]]: PrismaDelegate[EntityName]
}

View File

@ -1,2 +1,6 @@
import { prisma } from 'wasp/server'
import { prisma } from 'wasp/server'
import {
type UnauthenticatedOperationFor,
createUnauthenticatedOperation,
} from '../wrappers.js'

View File

@ -1,2 +1,6 @@
import { prisma } from 'wasp/server'
import { prisma } from 'wasp/server'
import {
type UnauthenticatedOperationFor,
createUnauthenticatedOperation,
} from '../wrappers.js'

View File

@ -0,0 +1,90 @@
import { _Awaited, _ReturnType } from '../../universal/types'
import {
_Entity,
UnauthenticatedOperationDefinition,
Payload,
} from '../_types'
// PRIVATE API (used in SDK)
// Explanation:
// - Custom `_Awaited` and `_ReturnType` - Read the comments above their
// definitions.
// - `Parameters<OperationDefinition> extends []` - Same reason as described here:
// https://github.com/wasp-lang/wasp/pull/1992/files#r1583040080
/**
* Constructs the unauthenticated operation's server-side API type from its
* definition.
*
* @template OperationDefinition The type of the unauthenticated operation's
* definition.
*/
export type UnauthenticatedOperationFor<
OperationDefinition extends GenericUnauthenticatedOperationDefinition
> = Parameters<OperationDefinition> extends []
? UnauthenticatedOperation<void, _Awaited<_ReturnType<OperationDefinition>>>
: UnauthenticatedOperation<
Parameters<OperationDefinition>[0],
_Awaited<_ReturnType<OperationDefinition>>
>
// PRIVATE API (used in SDK)
/**
* Creates the server-side API for an unauthenticated operation.
*
* @template OperationDefinition The type of the unauthenticated operation's definition.
* @param userOperation The unauthenticated operation's definition.
* @param entities The unauthenticated operation's entity map .
* @returns The server-side API for the provided unauthenticated operation.
*/
export function createUnauthenticatedOperation<
OperationDefinition extends GenericUnauthenticatedOperationDefinition
>(
userOperation: OperationDefinition,
entities: EntityMapFor<OperationDefinition>
): UnauthenticatedOperationFor<OperationDefinition> {
async function operation(payload: Parameters<OperationDefinition>[0]) {
return userOperation(payload, {
entities,
})
}
// This assertion is necessary because, when the Input is void, we want to present
// the function as not accepting a payload (which isn't consistent with how
// it's defined).
return operation as UnauthenticatedOperationFor<OperationDefinition>
}
/**
* Constructs the type for an unauthenticated operation's server-side API.
*
* @template Input The type of the payload the operation expects (must be
* `void` if the operation doesn't expect a payload).
* @template Output The type of the operation's return value.
*/
type UnauthenticatedOperation<Input, Output> =
[Input] extends [never]
? (args: unknown) => Promise<Output>
: [Input] extends [void]
? () => Promise<Output>
: (args: Input) => Promise<Output>
/**
* The principal type for an unauthenticated operation's definition (i.e., all
* unauthenticated operation definition types are a subtype of this type).
*
*/
type GenericUnauthenticatedOperationDefinition = UnauthenticatedOperationDefinition<
// NOTE(filip): Not quite sure I understand what's going on with Variance here.
_Entity[],
never,
Payload
>
/**
* Queries the entity map from the type of the operation's definition.
*
* @template OperationDefinition The type of the operation's definition.
*/
type EntityMapFor<OperationDefinition extends GenericUnauthenticatedOperationDefinition> =
Parameters<OperationDefinition>[1]["entities"]

View File

@ -143,6 +143,9 @@ waspCompile/.wasp/out/sdk/wasp/dist/server/operations/queries/index.js.map
waspCompile/.wasp/out/sdk/wasp/dist/server/operations/queries/types.d.ts
waspCompile/.wasp/out/sdk/wasp/dist/server/operations/queries/types.js
waspCompile/.wasp/out/sdk/wasp/dist/server/operations/queries/types.js.map
waspCompile/.wasp/out/sdk/wasp/dist/server/operations/wrappers.d.ts
waspCompile/.wasp/out/sdk/wasp/dist/server/operations/wrappers.js
waspCompile/.wasp/out/sdk/wasp/dist/server/operations/wrappers.js.map
waspCompile/.wasp/out/sdk/wasp/dist/server/types/index.d.ts
waspCompile/.wasp/out/sdk/wasp/dist/server/types/index.js
waspCompile/.wasp/out/sdk/wasp/dist/server/types/index.js.map
@ -178,6 +181,7 @@ waspCompile/.wasp/out/sdk/wasp/server/operations/actions/types.ts
waspCompile/.wasp/out/sdk/wasp/server/operations/index.ts
waspCompile/.wasp/out/sdk/wasp/server/operations/queries/index.ts
waspCompile/.wasp/out/sdk/wasp/server/operations/queries/types.ts
waspCompile/.wasp/out/sdk/wasp/server/operations/wrappers.ts
waspCompile/.wasp/out/sdk/wasp/server/types/index.ts
waspCompile/.wasp/out/sdk/wasp/server/utils.ts
waspCompile/.wasp/out/sdk/wasp/tsconfig.json

View File

@ -32,7 +32,7 @@
"file",
"../out/sdk/wasp/client/operations/actions/core.ts"
],
"d19dba04947e4015af69d90dd160ec5f4ed020bfa905bc37bcd5d980517097ae"
"ff3597c5f07015adf4dcf5cf6043d054989e76522fd59eb94bdaa34e9c9ea95f"
],
[
[
@ -46,7 +46,7 @@
"file",
"../out/sdk/wasp/client/operations/hooks.ts"
],
"18b73aae68fbe6774d4a9929e48b3d9fbd8acae9b811b31a076547f463e6e620"
"d1a8fccfb8207476b90708e8285d1455b33ff4e446749b33c3eb1a54dcfe2d41"
],
[
[
@ -81,7 +81,7 @@
"file",
"../out/sdk/wasp/client/operations/queries/core.ts"
],
"2229320d3541802817d12f2dc1226a0e683bf058ab27150ae4ba661c6891d257"
"7f842b7add5a2949a49981dac64dd5951457eb5b9d3c555f25f6e4f11c04f3b4"
],
[
[
@ -102,7 +102,7 @@
"file",
"../out/sdk/wasp/client/operations/rpc.ts"
],
"a396d0014651837eae36f83d5c36e730e6d389ee7ff41e72206cc6936419d576"
"63fb0670b2ccff4ad005bbb76597572a60e01f31b739d7bc764bb59c4f3c53d4"
],
[
[
@ -214,7 +214,7 @@
"file",
"../out/sdk/wasp/server/_types/index.ts"
],
"2eb94c60f2031ae3ea023de5aa938b3aeabba31388a7f8bdcdee432bbef3f517"
"e19d9927bb6f9d4a95641c01d3488d45dad5c8bf708b6573401e8ee9f4067995"
],
[
[
@ -270,7 +270,7 @@
"file",
"../out/sdk/wasp/server/operations/actions/index.ts"
],
"c67a0c7d8946f5c465edea2de78e78537384bd6f30ec4f4fd6dfe58243f4f36a"
"35fa55dbb38aa52924082f825b80c4b41be7371934466f6797aeef02b70baa31"
],
[
[
@ -291,7 +291,7 @@
"file",
"../out/sdk/wasp/server/operations/queries/index.ts"
],
"c67a0c7d8946f5c465edea2de78e78537384bd6f30ec4f4fd6dfe58243f4f36a"
"35fa55dbb38aa52924082f825b80c4b41be7371934466f6797aeef02b70baa31"
],
[
[
@ -300,6 +300,13 @@
],
"19f72a3a37efd1e29b0793caa7f379494ad236bb513c8c8804b5a8d305c45196"
],
[
[
"file",
"../out/sdk/wasp/server/operations/wrappers.ts"
],
"4f3ffd00d845664a0122a24d2a12279c0febd744214c7167e7d9dea41330e107"
],
[
[
"file",

View File

@ -37,7 +37,11 @@ export function createAction<BackendAction extends GenericBackendOperation>(
const action = (args) => internalAction(args, [])
action.internal = internalAction
return action as ActionFor<BackendAction>
// NOTE: I'm not sure why unknown is necessary here,
// it might have something to do with functions allowing evolving types,
// // while objects to not:
// https://www.typescriptlang.org/play/?#code/MYewdgzgLgBCBGArGBeGBvGBDAXDA5AGYgj4wC+AUAogHTyoHxYBO+llA9JzIQK5hgUAJbhsAG3EgA7hGxgYAUwBuIccuFgA5jCgBPAA6KY8PrBqKhMACYhFcsCCiVQkWPwVoAFAEpUAPgJiUkoPekZ8ZjYgA
return action as unknown as ActionFor<BackendAction>
}
// PRIVATE API

View File

@ -72,7 +72,11 @@ export function useAction<Input = unknown, Output = unknown>(
// clearly separate our opinionated API from React Query's lower-level
// advanced API (which users can also use)
const mutation = useMutation(mutationFn, options);
return (args) => mutation.mutateAsync(args);
// This assertion is necessary because, when the Input is void, we want to
// present the function as not accepting a payload (which isn't consistent
// with how it's defined).
return ((args: Input) => mutation.mutateAsync(args)) as typeof actionFn;
}
// PUBLIC API
@ -200,7 +204,7 @@ function makeOptimisticUpdateMutationFn<Input, Output, CachedData>(
CachedData
>[]
): typeof actionFn {
return function performActionWithOptimisticUpdates(item) {
return (function performActionWithOptimisticUpdates(item?: Input) {
const specificOptimisticUpdateDefinitions = optimisticUpdateDefinitions.map(
(generalDefinition) =>
getOptimisticUpdateDefinitionForSpecificItem(generalDefinition, item)
@ -209,7 +213,10 @@ function makeOptimisticUpdateMutationFn<Input, Output, CachedData>(
item,
specificOptimisticUpdateDefinitions
);
};
// This assertion is necessary because, when the Input is void, we want to
// present the function as not accepting a payload (which isn't consistent
// with how it's defined).
}) as typeof actionFn;
}
/**

View File

@ -1,6 +1,6 @@
import { Route } from 'wasp/client'
import type { _Awaited, _ReturnType } from 'wasp/universal/types'
import type {
import type {
GenericBackendOperation,
GenericOperationRpc,
OperationRpcFor,
@ -20,9 +20,9 @@ export function makeQueryCacheKey<Input, Output>(
query: Query<Input, Output>,
payload: Input
): (string | Input)[] {
return payload !== undefined ?
[...query.queryCacheKey, payload]
: query.queryCacheKey
return payload !== undefined ?
[...query.queryCacheKey, payload]
: query.queryCacheKey
}
// PRIVATE API (unsed in SDK)
@ -33,7 +33,7 @@ export function createQuery<BackendQuery extends GenericBackendOperation>(
const queryRoute = makeOperationRoute(relativeQueryPath)
const queryCacheKey = [relativeQueryPath]
const queryFn: QueryFunctionFor<BackendQuery> = async (queryArgs) => {
const queryFn = (async (queryArgs) => {
const serverResult = await callOperation(queryRoute, queryArgs)
// todo: The full queryCacheKey is constructed in two places, both here and
// inside the useQuery hook. See
@ -43,7 +43,10 @@ export function createQuery<BackendQuery extends GenericBackendOperation>(
(result, update) => update(result),
serverResult,
)
}
// This assertion is necessary because, when the Input is void, we want to
// present the function as not accepting a payload (which isn't consistent
// with how it's defined).
}) as QueryFunctionFor<BackendQuery>
return buildAndRegisterQuery(
queryFn,
@ -54,12 +57,12 @@ export function createQuery<BackendQuery extends GenericBackendOperation>(
// PRIVATE API (used in SDK)
export function buildAndRegisterQuery<QF extends GenericOperationRpc>(
queryFn: QF,
{ queryCacheKey, queryRoute, entitiesUsed }:
{ queryCacheKey: string[], queryRoute: Route, entitiesUsed: string[] }
{ queryCacheKey, queryRoute, entitiesUsed }:
{ queryCacheKey: string[], queryRoute: Route, entitiesUsed: string[] }
): QueryForFunction<QF> {
const query = queryFn as QueryForFunction<QF>
query.queryCacheKey = queryCacheKey
query.queryCacheKey = queryCacheKey
query.route = queryRoute
addResourcesUsedByQuery(query.queryCacheKey, entitiesUsed)
@ -77,7 +80,7 @@ export type QueryFor<BackendQuery extends GenericBackendOperation> =
/**
* Constructs the client Query function type from the type of the Query's
* definition on the backend.
*/
*/
type QueryFunctionFor<BackendQuery extends GenericBackendOperation> =
OperationRpcFor<BackendQuery>

View File

@ -77,4 +77,6 @@ export type GenericOperationRpc = (args: never) => Promise<unknown>
// Read this to understand the type: https://github.com/wasp-lang/wasp/pull/1090#discussion_r1159732471
type ClientOperation<Input, Output> = [Input] extends [never]
? (args?: unknown) => Promise<Output>
: (args: Input) => Promise<Output>;
: [Input] extends [void]
? () => Promise<Output>
: (args: Input) => Promise<Output>

View File

@ -26,6 +26,10 @@ export function createAction(relativeActionRoute, entitiesUsed) {
// we can always hide it using a Symbol.
const action = (args) => internalAction(args, []);
action.internal = internalAction;
// NOTE: I'm not sure why unknown is necessary here,
// it might have something to do with functions allowing evolving types,
// // while objects to not:
// https://www.typescriptlang.org/play/?#code/MYewdgzgLgBCBGArGBeGBvGBDAXDA5AGYgj4wC+AUAogHTyoHxYBO+llA9JzIQK5hgUAJbhsAG3EgA7hGxgYAUwBuIccuFgA5jCgBPAA6KY8PrBqKhMACYhFcsCCiVQkWPwVoAFAEpUAPgJiUkoPekZ8ZjYgA
return action;
}
//# sourceMappingURL=core.js.map

View File

@ -1 +1 @@
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../../client/operations/actions/core.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACxE,OAAO,EACL,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,0BAA0B,CAAA;AAEjC,cAAc;AACd,MAAM,UAAU,YAAY,CAC1B,mBAA2B,EAC3B,YAAuB;IAEvB,MAAM,WAAW,GAAG,kBAAkB,CAAC,mBAAmB,CAAC,CAAA;IAE3D,KAAK,UAAU,cAAc,CAAC,IAAI,EAAE,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CAAC;IAED,0EAA0E;IAC1E,yEAAyE;IACzE,6EAA6E;IAC7E,yEAAyE;IACzE,gBAAgB;IAChB,EAAE;IACF,0EAA0E;IAC1E,8EAA8E;IAC9E,wCAAwC;IACxC,MAAM,MAAM,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;IACjD,MAAM,CAAC,QAAQ,GAAG,cAAc,CAAA;IAEhC,oDAAoD;IACpD,wEAAwE;IACxE,2BAA2B;IAC3B,2MAA2M;IAC3M,OAAO,MAA6C,CAAA;AACtD,CAAC"}

View File

@ -39,7 +39,10 @@ export function useAction(actionFn, actionOptions) {
// clearly separate our opinionated API from React Query's lower-level
// advanced API (which users can also use)
const mutation = useMutation(mutationFn, options);
return (args) => mutation.mutateAsync(args);
// This assertion is necessary because, when the Input is void, we want to
// present the function as not accepting a payload (which isn't consistent
// with how it's defined).
return ((args) => mutation.mutateAsync(args));
}
/**
* Translates/Desugars a public optimistic update definition object into a
@ -76,10 +79,13 @@ function translateToInternalDefinition(publicOptimisticUpdateDefinition) {
* @returns An decorated action which performs optimistic updates.
*/
function makeOptimisticUpdateMutationFn(actionFn, optimisticUpdateDefinitions) {
return function performActionWithOptimisticUpdates(item) {
return (function performActionWithOptimisticUpdates(item) {
const specificOptimisticUpdateDefinitions = optimisticUpdateDefinitions.map((generalDefinition) => getOptimisticUpdateDefinitionForSpecificItem(generalDefinition, item));
return actionFn.internal(item, specificOptimisticUpdateDefinitions);
};
// This assertion is necessary because, when the Input is void, we want to
// present the function as not accepting a payload (which isn't consistent
// with how it's defined).
});
}
/**
* Given a ReactQuery query client and our internal definition of optimistic

View File

@ -1 +1 @@
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../client/operations/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,WAAW,EAEX,cAAc,EACd,QAAQ,IAAI,UAAU,GAEvB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,iBAA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;;;;;GAWG;AACH,SAAS,4CAA4C,CACnD,0BAGC,EACD,IAAiB;IAEjB,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,0BAA0B,CAAC;IAChE,OAAO;QACL,QAAQ,EAAE,WAAW,CAAC,IAAI,CAAC;QAC3B,WAAW,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,CAAC;KAC7C,CAAC;AACJ,CAAC;AAED,qEAAqE;AACrE,+EAA+E;AAC/E;;;;;;GAMG;AACH,SAAS,0BAA0B,CACjC,cAAgD;IAEhD,MAAM,CAAC,OAAO,EAAE,GAAG,SAAS,CAAC,GAAG,cAAc,CAAC;IAC/C,OAAO,CAAC,GAAI,OAAe,CAAC,aAAa,EAAE,GAAG,SAAS,CAAC,CAAC;AAC3D,CAAC"}

View File

@ -12,14 +12,17 @@ export function makeQueryCacheKey(query, payload) {
export function createQuery(relativeQueryPath, entitiesUsed) {
const queryRoute = makeOperationRoute(relativeQueryPath);
const queryCacheKey = [relativeQueryPath];
const queryFn = async (queryArgs) => {
const queryFn = (async (queryArgs) => {
const serverResult = await callOperation(queryRoute, queryArgs);
// todo: The full queryCacheKey is constructed in two places, both here and
// inside the useQuery hook. See
// https://github.com/wasp-lang/wasp/issues/2017
const queryCacheKey = makeQueryCacheKey(queryFn, queryArgs);
return getActiveOptimisticUpdates(queryCacheKey).reduce((result, update) => update(result), serverResult);
};
// This assertion is necessary because, when the Input is void, we want to
// present the function as not accepting a payload (which isn't consistent
// with how it's defined).
});
return buildAndRegisterQuery(queryFn, { queryCacheKey, queryRoute, entitiesUsed });
}
// PRIVATE API (used in SDK)

View File

@ -1 +1 @@
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../../client/operations/queries/core.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACxE,OAAO,EACL,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,uB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AAA;AACH,CAAC;AAED,4BAA4B;AAC5B,MAAM,UAAU,qBAAqB,CACnC,OAAW,EACX,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAC+B;IAExE,MAAM,KAAK,GAAG,OAA+B,CAAA;IAE7C,KAAK,CAAC,aAAa,GAAG,aAAa,CAAA;IACnC,KAAK,CAAC,KAAK,GAAG,UAAU,CAAA;IACxB,uBAAuB,CAAC,KAAK,CAAC,aAAa,EAAE,YAAY,CAAC,CAAA;IAE1D,OAAO,KAAK,CAAA;AACd,CAAC"}

View File

@ -34,5 +34,5 @@ export type GenericBackendOperation = (args: never, context: any) => unknown;
* A supertype of all possible frontend RPC function types.
*/
export type GenericOperationRpc = (args: never) => Promise<unknown>;
type ClientOperation<Input, Output> = [Input] extends [never] ? (args?: unknown) => Promise<Output> : (args: Input) => Promise<Output>;
type ClientOperation<Input, Output> = [Input] extends [never] ? (args?: unknown) => Promise<Output> : [Input] extends [void] ? () => Promise<Output> : (args: Input) => Promise<Output>;
export {};

View File

@ -1,15 +1,15 @@
import { type Expand } from 'wasp/universal/types';
import { type Request, type Response } from 'express';
import { type ParamsDictionary as ExpressParams, type Query as ExpressQuery } from 'express-serve-static-core';
import { type _Entity } from "./taggedEntities";
import { type Payload } from "./serialization";
import { type _Entity } from './taggedEntities';
import { type Payload } from './serialization';
export * from "./taggedEntities";
export * from "./serialization";
export type Query<Entities extends _Entity[], Input extends Payload, Output extends Payload> = Operation<Entities, Input, Output>;
export type Action<Entities extends _Entity[], Input extends Payload, Output extends Payload> = Operation<Entities, Input, Output>;
type Operation<Entities extends _Entity[], Input, Output> = (args: Input, context: Context<Entities>) => Output | Promise<Output>;
export type UnauthenticatedQueryDefinition<Entities extends _Entity[], Input extends Payload, Output extends Payload> = UnauthenticatedOperationDefinition<Entities, Input, Output>;
export type UnauthenticatedActionDefinition<Entities extends _Entity[], Input extends Payload, Output extends Payload> = UnauthenticatedOperationDefinition<Entities, Input, Output>;
export type UnauthenticatedOperationDefinition<Entities extends _Entity[], Input extends Payload, Output extends Payload> = (args: Input, context: Context<Entities>) => Output | Promise<Output>;
export type Api<Entities extends _Entity[], Params extends ExpressParams, ResBody, ReqBody, ReqQuery extends ExpressQuery, Locals extends Record<string, any>> = (req: Request<Params, ResBody, ReqBody, ReqQuery, Locals>, res: Response<ResBody, Locals>, context: Context<Entities>) => void;
type EntityMap<Entities extends _Entity[]> = {
export type EntityMap<Entities extends _Entity[]> = {
[EntityName in Entities[number]["_entityName"]]: PrismaDelegate[EntityName];
};
export type PrismaDelegate = {};

View File

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/_types/index.ts"],"names":[],"mappings":"AAOA,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA"}
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/_types/index.ts"],"names":[],"mappings":"AAUA,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA"}

View File

@ -0,0 +1,42 @@
import { _Awaited, _ReturnType } from '../../universal/types';
import { _Entity, UnauthenticatedOperationDefinition, Payload } from '../_types';
/**
* Constructs the unauthenticated operation's server-side API type from its
* definition.
*
* @template OperationDefinition The type of the unauthenticated operation's
* definition.
*/
export type UnauthenticatedOperationFor<OperationDefinition extends GenericUnauthenticatedOperationDefinition> = Parameters<OperationDefinition> extends [] ? UnauthenticatedOperation<void, _Awaited<_ReturnType<OperationDefinition>>> : UnauthenticatedOperation<Parameters<OperationDefinition>[0], _Awaited<_ReturnType<OperationDefinition>>>;
/**
* Creates the server-side API for an unauthenticated operation.
*
* @template OperationDefinition The type of the unauthenticated operation's definition.
* @param userOperation The unauthenticated operation's definition.
* @param entities The unauthenticated operation's entity map .
* @returns The server-side API for the provided unauthenticated operation.
*/
export declare function createUnauthenticatedOperation<OperationDefinition extends GenericUnauthenticatedOperationDefinition>(userOperation: OperationDefinition, entities: EntityMapFor<OperationDefinition>): UnauthenticatedOperationFor<OperationDefinition>;
/**
* Constructs the type for an unauthenticated operation's server-side API.
*
* @template Input The type of the payload the operation expects (must be
* `void` if the operation doesn't expect a payload).
* @template Output The type of the operation's return value.
*/
type UnauthenticatedOperation<Input, Output> = [
Input
] extends [never] ? (args: unknown) => Promise<Output> : [Input] extends [void] ? () => Promise<Output> : (args: Input) => Promise<Output>;
/**
* The principal type for an unauthenticated operation's definition (i.e., all
* unauthenticated operation definition types are a subtype of this type).
*
*/
type GenericUnauthenticatedOperationDefinition = UnauthenticatedOperationDefinition<_Entity[], never, Payload>;
/**
* Queries the entity map from the type of the operation's definition.
*
* @template OperationDefinition The type of the operation's definition.
*/
type EntityMapFor<OperationDefinition extends GenericUnauthenticatedOperationDefinition> = Parameters<OperationDefinition>[1]["entities"];
export {};

View File

@ -0,0 +1,21 @@
// PRIVATE API (used in SDK)
/**
* Creates the server-side API for an unauthenticated operation.
*
* @template OperationDefinition The type of the unauthenticated operation's definition.
* @param userOperation The unauthenticated operation's definition.
* @param entities The unauthenticated operation's entity map .
* @returns The server-side API for the provided unauthenticated operation.
*/
export function createUnauthenticatedOperation(userOperation, entities) {
async function operation(payload) {
return userOperation(payload, {
entities,
});
}
// This assertion is necessary because, when the Input is void, we want to present
// the function as not accepting a payload (which isn't consistent with how
// it's defined).
return operation;
}
//# sourceMappingURL=wrappers.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"wrappers.js","sourceRoot":"","sources":["../../../server/operations/wrappers.ts"],"names":[],"mappings":"AA8BA,4BAA4B;AAC5B;;;;;;;GAOG;AACH,MAAM,UAAU,8BAA8B,CAG5C,aAAkC,EAClC,QAA2C;IAE3C,KAAK,UAAU,SAAS,CAAC,OAA2C;QAClE,OAAO,aAAa,CAAC,OAAO,EAAE;YAC5B,QAAQ;SACT,CAAC,CAAA;IACJ,CAAC;IACD,kFAAkF;IAClF,2EAA2E;IAC3E,iBAAiB;IACjB,OAAO,SAA6D,CAAA;AACtE,CAAC"}

View File

@ -1,23 +1,33 @@
import { type Expand } from 'wasp/universal/types';
import { type Expand } from 'wasp/universal/types'
import { type Request, type Response } from 'express'
import { type ParamsDictionary as ExpressParams, type Query as ExpressQuery } from 'express-serve-static-core'
import {
type ParamsDictionary as ExpressParams,
type Query as ExpressQuery,
} from 'express-serve-static-core'
import { prisma } from 'wasp/server'
import { type _Entity } from "./taggedEntities"
import { type Payload } from "./serialization";
import { type _Entity } from './taggedEntities'
import { type Payload } from './serialization'
export * from "./taggedEntities"
export * from "./serialization"
export type Query<Entities extends _Entity[], Input extends Payload, Output extends Payload> =
Operation<Entities, Input, Output>
export type UnauthenticatedQueryDefinition<
Entities extends _Entity[],
Input extends Payload,
Output extends Payload
> = UnauthenticatedOperationDefinition<Entities, Input, Output>
export type Action<Entities extends _Entity[], Input extends Payload, Output extends Payload> =
Operation<Entities, Input, Output>
export type UnauthenticatedActionDefinition<
Entities extends _Entity[],
Input extends Payload,
Output extends Payload
> = UnauthenticatedOperationDefinition<Entities, Input, Output>
type Operation<Entities extends _Entity[], Input, Output> = (
args: Input,
context: Context<Entities>,
) => Output | Promise<Output>
export type UnauthenticatedOperationDefinition<
Entities extends _Entity[],
Input extends Payload,
Output extends Payload
> = (args: Input, context: Context<Entities>) => Output | Promise<Output>
export type Api<
Entities extends _Entity[],
@ -32,7 +42,7 @@ export type Api<
context: Context<Entities>,
) => void
type EntityMap<Entities extends _Entity[]> = {
export type EntityMap<Entities extends _Entity[]> = {
[EntityName in Entities[number]["_entityName"]]: PrismaDelegate[EntityName]
}

View File

@ -1,2 +1,6 @@
import { prisma } from 'wasp/server'
import { prisma } from 'wasp/server'
import {
type UnauthenticatedOperationFor,
createUnauthenticatedOperation,
} from '../wrappers.js'

View File

@ -1,2 +1,6 @@
import { prisma } from 'wasp/server'
import { prisma } from 'wasp/server'
import {
type UnauthenticatedOperationFor,
createUnauthenticatedOperation,
} from '../wrappers.js'

View File

@ -0,0 +1,90 @@
import { _Awaited, _ReturnType } from '../../universal/types'
import {
_Entity,
UnauthenticatedOperationDefinition,
Payload,
} from '../_types'
// PRIVATE API (used in SDK)
// Explanation:
// - Custom `_Awaited` and `_ReturnType` - Read the comments above their
// definitions.
// - `Parameters<OperationDefinition> extends []` - Same reason as described here:
// https://github.com/wasp-lang/wasp/pull/1992/files#r1583040080
/**
* Constructs the unauthenticated operation's server-side API type from its
* definition.
*
* @template OperationDefinition The type of the unauthenticated operation's
* definition.
*/
export type UnauthenticatedOperationFor<
OperationDefinition extends GenericUnauthenticatedOperationDefinition
> = Parameters<OperationDefinition> extends []
? UnauthenticatedOperation<void, _Awaited<_ReturnType<OperationDefinition>>>
: UnauthenticatedOperation<
Parameters<OperationDefinition>[0],
_Awaited<_ReturnType<OperationDefinition>>
>
// PRIVATE API (used in SDK)
/**
* Creates the server-side API for an unauthenticated operation.
*
* @template OperationDefinition The type of the unauthenticated operation's definition.
* @param userOperation The unauthenticated operation's definition.
* @param entities The unauthenticated operation's entity map .
* @returns The server-side API for the provided unauthenticated operation.
*/
export function createUnauthenticatedOperation<
OperationDefinition extends GenericUnauthenticatedOperationDefinition
>(
userOperation: OperationDefinition,
entities: EntityMapFor<OperationDefinition>
): UnauthenticatedOperationFor<OperationDefinition> {
async function operation(payload: Parameters<OperationDefinition>[0]) {
return userOperation(payload, {
entities,
})
}
// This assertion is necessary because, when the Input is void, we want to present
// the function as not accepting a payload (which isn't consistent with how
// it's defined).
return operation as UnauthenticatedOperationFor<OperationDefinition>
}
/**
* Constructs the type for an unauthenticated operation's server-side API.
*
* @template Input The type of the payload the operation expects (must be
* `void` if the operation doesn't expect a payload).
* @template Output The type of the operation's return value.
*/
type UnauthenticatedOperation<Input, Output> =
[Input] extends [never]
? (args: unknown) => Promise<Output>
: [Input] extends [void]
? () => Promise<Output>
: (args: Input) => Promise<Output>
/**
* The principal type for an unauthenticated operation's definition (i.e., all
* unauthenticated operation definition types are a subtype of this type).
*
*/
type GenericUnauthenticatedOperationDefinition = UnauthenticatedOperationDefinition<
// NOTE(filip): Not quite sure I understand what's going on with Variance here.
_Entity[],
never,
Payload
>
/**
* Queries the entity map from the type of the operation's definition.
*
* @template OperationDefinition The type of the operation's definition.
*/
type EntityMapFor<OperationDefinition extends GenericUnauthenticatedOperationDefinition> =
Parameters<OperationDefinition>[1]["entities"]

View File

@ -352,6 +352,9 @@ waspComplexTest/.wasp/out/sdk/wasp/dist/server/operations/queries/index.js.map
waspComplexTest/.wasp/out/sdk/wasp/dist/server/operations/queries/types.d.ts
waspComplexTest/.wasp/out/sdk/wasp/dist/server/operations/queries/types.js
waspComplexTest/.wasp/out/sdk/wasp/dist/server/operations/queries/types.js.map
waspComplexTest/.wasp/out/sdk/wasp/dist/server/operations/wrappers.d.ts
waspComplexTest/.wasp/out/sdk/wasp/dist/server/operations/wrappers.js
waspComplexTest/.wasp/out/sdk/wasp/dist/server/operations/wrappers.js.map
waspComplexTest/.wasp/out/sdk/wasp/dist/server/types/index.d.ts
waspComplexTest/.wasp/out/sdk/wasp/dist/server/types/index.js
waspComplexTest/.wasp/out/sdk/wasp/dist/server/types/index.js.map
@ -416,6 +419,7 @@ waspComplexTest/.wasp/out/sdk/wasp/server/operations/actions/types.ts
waspComplexTest/.wasp/out/sdk/wasp/server/operations/index.ts
waspComplexTest/.wasp/out/sdk/wasp/server/operations/queries/index.ts
waspComplexTest/.wasp/out/sdk/wasp/server/operations/queries/types.ts
waspComplexTest/.wasp/out/sdk/wasp/server/operations/wrappers.ts
waspComplexTest/.wasp/out/sdk/wasp/server/types/index.ts
waspComplexTest/.wasp/out/sdk/wasp/server/utils.ts
waspComplexTest/.wasp/out/sdk/wasp/tsconfig.json

View File

@ -228,21 +228,21 @@
"file",
"../out/sdk/wasp/client/operations/actions/core.ts"
],
"d19dba04947e4015af69d90dd160ec5f4ed020bfa905bc37bcd5d980517097ae"
"ff3597c5f07015adf4dcf5cf6043d054989e76522fd59eb94bdaa34e9c9ea95f"
],
[
[
"file",
"../out/sdk/wasp/client/operations/actions/index.ts"
],
"614384a79d3c4f27fefadf4c7accb0f795554f57fa42f3fb643b948203e35790"
"f830b21416e19ae6ff047d7ad8259ef7781d500727118f32b5c17d642a49a03f"
],
[
[
"file",
"../out/sdk/wasp/client/operations/hooks.ts"
],
"18b73aae68fbe6774d4a9929e48b3d9fbd8acae9b811b31a076547f463e6e620"
"d1a8fccfb8207476b90708e8285d1455b33ff4e446749b33c3eb1a54dcfe2d41"
],
[
[
@ -277,14 +277,14 @@
"file",
"../out/sdk/wasp/client/operations/queries/core.ts"
],
"2229320d3541802817d12f2dc1226a0e683bf058ab27150ae4ba661c6891d257"
"7f842b7add5a2949a49981dac64dd5951457eb5b9d3c555f25f6e4f11c04f3b4"
],
[
[
"file",
"../out/sdk/wasp/client/operations/queries/index.ts"
],
"f086e3b7f43d3b4fdd7b8a4e32907d245b4cddf837c7f777b07fc1d3577c067c"
"b01c3ca84af658eaae0db643912f6eebcf6cca34c6bb3d163b804f386b11c2a2"
],
[
[
@ -298,7 +298,7 @@
"file",
"../out/sdk/wasp/client/operations/rpc.ts"
],
"a396d0014651837eae36f83d5c36e730e6d389ee7ff41e72206cc6936419d576"
"63fb0670b2ccff4ad005bbb76597572a60e01f31b739d7bc764bb59c4f3c53d4"
],
[
[
@ -494,7 +494,7 @@
"file",
"../out/sdk/wasp/server/_types/index.ts"
],
"f436c855b151a95179fd59193b8fe426ae0138265be3cef450e430302c3aeafb"
"0bd32f0d0ab8f76d5d73898757e08a582a6ab54e1585d6fb06ef8200a7df3f39"
],
[
[
@ -557,7 +557,7 @@
"file",
"../out/sdk/wasp/server/crud/tasks.ts"
],
"828dca19bb70fe4e7859d9763d242bead6861e27a4d044ae0a53bb2885a0f329"
"2cba96b41fe246ae5f9813a155cfb2dd6a0d9012fc9e3732ddbc9d4a3f625f42"
],
[
[
@ -683,14 +683,14 @@
"file",
"../out/sdk/wasp/server/operations/actions/index.ts"
],
"fde699b5ff9854279e08a203443cbb2617bf0b9287be1de197642d005e00487a"
"236e3b4a8c6c8c516cb7b4349a844b658877f4be3eb941516b806e005b36e7e9"
],
[
[
"file",
"../out/sdk/wasp/server/operations/actions/types.ts"
],
"d8ca5d71475fc4e4548cb3d3249dba3ae36142252f8efa1852a77edb86779198"
"168d20cd6e0ba3e5f9bff378904b8f5ae4f69a1bf5aa060840042892a9677fe6"
],
[
[
@ -704,14 +704,21 @@
"file",
"../out/sdk/wasp/server/operations/queries/index.ts"
],
"6e46c51751c22f1de5c9c6a347f00cd07b0eda1a24bc7e2fbfb7cd421e023cfc"
"051ce9dae557b1e3014eb639b40f3ec8bdd042466ba1758f28a62a3942ecbd25"
],
[
[
"file",
"../out/sdk/wasp/server/operations/queries/types.ts"
],
"26d0b0bad652d9a51af568f95e361e45860181ad2816a8f1d3113fdf2fdd3c6e"
"fc3e799d4d01077eaf56205cba97e13814192eef863abd605b9fed05fcb53669"
],
[
[
"file",
"../out/sdk/wasp/server/operations/wrappers.ts"
],
"d2ae69bd910aa1238c6f87a6d4f6ca88e187935059820a8bd3860cbc9f5e1d3b"
],
[
[
@ -844,7 +851,7 @@
"file",
"server/src/actions/mySpecialAction.ts"
],
"d306e32442616e08a6a2bbf4fce881a983d5db12b6de648313a83e362dcc552a"
"4be6c9b5a013b7dca6a6897303a3f63667f30ee58234d2edcec0761eb7f83d91"
],
[
[
@ -998,7 +1005,7 @@
"file",
"server/src/queries/mySpecialQuery.ts"
],
"4f907aed444b1778b919bb2021a44a53f2282d238e65e843670d2e786a623a71"
"c595702e1fc397f0682477048c13c73755345ba6eee224e6e4137c6629b78aaf"
],
[
[

View File

@ -37,7 +37,11 @@ export function createAction<BackendAction extends GenericBackendOperation>(
const action = (args) => internalAction(args, [])
action.internal = internalAction
return action as ActionFor<BackendAction>
// NOTE: I'm not sure why unknown is necessary here,
// it might have something to do with functions allowing evolving types,
// // while objects to not:
// https://www.typescriptlang.org/play/?#code/MYewdgzgLgBCBGArGBeGBvGBDAXDA5AGYgj4wC+AUAogHTyoHxYBO+llA9JzIQK5hgUAJbhsAG3EgA7hGxgYAUwBuIccuFgA5jCgBPAA6KY8PrBqKhMACYhFcsCCiVQkWPwVoAFAEpUAPgJiUkoPekZ8ZjYgA
return action as unknown as ActionFor<BackendAction>
}
// PRIVATE API

View File

@ -1,8 +1,8 @@
import { type ActionFor, createAction } from './core'
import { MySpecialAction } from 'wasp/server/operations/actions'
import { MySpecialAction_ext } from 'wasp/server/operations/actions'
// PUBLIC API
export const mySpecialAction: ActionFor<MySpecialAction> = createAction<MySpecialAction>(
export const mySpecialAction: ActionFor<MySpecialAction_ext> = createAction<MySpecialAction_ext>(
'operations/my-special-action',
['User'],
)

View File

@ -72,7 +72,11 @@ export function useAction<Input = unknown, Output = unknown>(
// clearly separate our opinionated API from React Query's lower-level
// advanced API (which users can also use)
const mutation = useMutation(mutationFn, options);
return (args) => mutation.mutateAsync(args);
// This assertion is necessary because, when the Input is void, we want to
// present the function as not accepting a payload (which isn't consistent
// with how it's defined).
return ((args: Input) => mutation.mutateAsync(args)) as typeof actionFn;
}
// PUBLIC API
@ -200,7 +204,7 @@ function makeOptimisticUpdateMutationFn<Input, Output, CachedData>(
CachedData
>[]
): typeof actionFn {
return function performActionWithOptimisticUpdates(item) {
return (function performActionWithOptimisticUpdates(item?: Input) {
const specificOptimisticUpdateDefinitions = optimisticUpdateDefinitions.map(
(generalDefinition) =>
getOptimisticUpdateDefinitionForSpecificItem(generalDefinition, item)
@ -209,7 +213,10 @@ function makeOptimisticUpdateMutationFn<Input, Output, CachedData>(
item,
specificOptimisticUpdateDefinitions
);
};
// This assertion is necessary because, when the Input is void, we want to
// present the function as not accepting a payload (which isn't consistent
// with how it's defined).
}) as typeof actionFn;
}
/**

View File

@ -1,6 +1,6 @@
import { Route } from 'wasp/client'
import type { _Awaited, _ReturnType } from 'wasp/universal/types'
import type {
import type {
GenericBackendOperation,
GenericOperationRpc,
OperationRpcFor,
@ -20,9 +20,9 @@ export function makeQueryCacheKey<Input, Output>(
query: Query<Input, Output>,
payload: Input
): (string | Input)[] {
return payload !== undefined ?
[...query.queryCacheKey, payload]
: query.queryCacheKey
return payload !== undefined ?
[...query.queryCacheKey, payload]
: query.queryCacheKey
}
// PRIVATE API (unsed in SDK)
@ -33,7 +33,7 @@ export function createQuery<BackendQuery extends GenericBackendOperation>(
const queryRoute = makeOperationRoute(relativeQueryPath)
const queryCacheKey = [relativeQueryPath]
const queryFn: QueryFunctionFor<BackendQuery> = async (queryArgs) => {
const queryFn = (async (queryArgs) => {
const serverResult = await callOperation(queryRoute, queryArgs)
// todo: The full queryCacheKey is constructed in two places, both here and
// inside the useQuery hook. See
@ -43,7 +43,10 @@ export function createQuery<BackendQuery extends GenericBackendOperation>(
(result, update) => update(result),
serverResult,
)
}
// This assertion is necessary because, when the Input is void, we want to
// present the function as not accepting a payload (which isn't consistent
// with how it's defined).
}) as QueryFunctionFor<BackendQuery>
return buildAndRegisterQuery(
queryFn,
@ -54,12 +57,12 @@ export function createQuery<BackendQuery extends GenericBackendOperation>(
// PRIVATE API (used in SDK)
export function buildAndRegisterQuery<QF extends GenericOperationRpc>(
queryFn: QF,
{ queryCacheKey, queryRoute, entitiesUsed }:
{ queryCacheKey: string[], queryRoute: Route, entitiesUsed: string[] }
{ queryCacheKey, queryRoute, entitiesUsed }:
{ queryCacheKey: string[], queryRoute: Route, entitiesUsed: string[] }
): QueryForFunction<QF> {
const query = queryFn as QueryForFunction<QF>
query.queryCacheKey = queryCacheKey
query.queryCacheKey = queryCacheKey
query.route = queryRoute
addResourcesUsedByQuery(query.queryCacheKey, entitiesUsed)
@ -77,7 +80,7 @@ export type QueryFor<BackendQuery extends GenericBackendOperation> =
/**
* Constructs the client Query function type from the type of the Query's
* definition on the backend.
*/
*/
type QueryFunctionFor<BackendQuery extends GenericBackendOperation> =
OperationRpcFor<BackendQuery>

View File

@ -1,8 +1,8 @@
import { type QueryFor, createQuery } from './core'
import { MySpecialQuery } from 'wasp/server/operations/queries'
import { MySpecialQuery_ext } from 'wasp/server/operations/queries'
// PUBLIC API
export const mySpecialQuery: QueryFor<MySpecialQuery> = createQuery<MySpecialQuery>(
export const mySpecialQuery: QueryFor<MySpecialQuery_ext> = createQuery<MySpecialQuery_ext>(
'operations/my-special-query',
['User'],
)

View File

@ -77,4 +77,6 @@ export type GenericOperationRpc = (args: never) => Promise<unknown>
// Read this to understand the type: https://github.com/wasp-lang/wasp/pull/1090#discussion_r1159732471
type ClientOperation<Input, Output> = [Input] extends [never]
? (args?: unknown) => Promise<Output>
: (args: Input) => Promise<Output>;
: [Input] extends [void]
? () => Promise<Output>
: (args: Input) => Promise<Output>

View File

@ -26,6 +26,10 @@ export function createAction(relativeActionRoute, entitiesUsed) {
// we can always hide it using a Symbol.
const action = (args) => internalAction(args, []);
action.internal = internalAction;
// NOTE: I'm not sure why unknown is necessary here,
// it might have something to do with functions allowing evolving types,
// // while objects to not:
// https://www.typescriptlang.org/play/?#code/MYewdgzgLgBCBGArGBeGBvGBDAXDA5AGYgj4wC+AUAogHTyoHxYBO+llA9JzIQK5hgUAJbhsAG3EgA7hGxgYAUwBuIccuFgA5jCgBPAA6KY8PrBqKhMACYhFcsCCiVQkWPwVoAFAEpUAPgJiUkoPekZ8ZjYgA
return action;
}
//# sourceMappingURL=core.js.map

View File

@ -1 +1 @@
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../../client/operations/actions/core.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACxE,OAAO,EACL,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,0BAA0B,CAAA;AAEjC,cAAc;AACd,MAAM,UAAU,YAAY,CAC1B,mBAA2B,EAC3B,YAAuB;IAEvB,MAAM,WAAW,GAAG,kBAAkB,CAAC,mBAAmB,CAAC,CAAA;IAE3D,KAAK,UAAU,cAAc,CAAC,IAAI,EAAE,mCAAmC;QACrE,wBAAwB,CAAC,mCAAmC,CAAC,CAAA;QAC7D,IAAI,CAAC;YACH,yEAAyE;YACzE,wEAAwE;YACxE,kCAAkC;YAClC,OAAO,MAAM,aAAa,CAAC,WAAW,EAAE,IAAI,C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CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;IACjD,MAAM,CAAC,QAAQ,GAAG,cAAc,CAAA;IAEhC,oDAAoD;IACpD,wEAAwE;IACxE,2BAA2B;IAC3B,2MAA2M;IAC3M,OAAO,MAA6C,CAAA;AACtD,CAAC"}

View File

@ -1,3 +1,3 @@
import { type ActionFor } from './core';
import { MySpecialAction } from 'wasp/server/operations/actions';
export declare const mySpecialAction: ActionFor<MySpecialAction>;
import { MySpecialAction_ext } from 'wasp/server/operations/actions';
export declare const mySpecialAction: ActionFor<MySpecialAction_ext>;

View File

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../client/operations/actions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,YAAY,EAAE,MAAM,QAAQ,CAAA;AAGrD,aAAa;AACb,MAAM,CAAC,MAAM,eAAe,GAA+B,YAAY,CACrE,8BAA8B,EAC9B,CAAC,MAAM,CAAC,CACT,CAAA"}
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../client/operations/actions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,YAAY,EAAE,MAAM,QAAQ,CAAA;AAGrD,aAAa;AACb,MAAM,CAAC,MAAM,eAAe,GAAmC,YAAY,CACzE,8BAA8B,EAC9B,CAAC,MAAM,CAAC,CACT,CAAA"}

View File

@ -39,7 +39,10 @@ export function useAction(actionFn, actionOptions) {
// clearly separate our opinionated API from React Query's lower-level
// advanced API (which users can also use)
const mutation = useMutation(mutationFn, options);
return (args) => mutation.mutateAsync(args);
// This assertion is necessary because, when the Input is void, we want to
// present the function as not accepting a payload (which isn't consistent
// with how it's defined).
return ((args) => mutation.mutateAsync(args));
}
/**
* Translates/Desugars a public optimistic update definition object into a
@ -76,10 +79,13 @@ function translateToInternalDefinition(publicOptimisticUpdateDefinition) {
* @returns An decorated action which performs optimistic updates.
*/
function makeOptimisticUpdateMutationFn(actionFn, optimisticUpdateDefinitions) {
return function performActionWithOptimisticUpdates(item) {
return (function performActionWithOptimisticUpdates(item) {
const specificOptimisticUpdateDefinitions = optimisticUpdateDefinitions.map((generalDefinition) => getOptimisticUpdateDefinitionForSpecificItem(generalDefinition, item));
return actionFn.internal(item, specificOptimisticUpdateDefinitions);
};
// This assertion is necessary because, when the Input is void, we want to
// present the function as not accepting a payload (which isn't consistent
// with how it's defined).
});
}
/**
* Given a ReactQuery query client and our internal definition of optimistic

View File

@ -1 +1 @@
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../client/operations/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,WAAW,EAEX,cAAc,EACd,QAAQ,IAAI,UAAU,GAEvB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAErD,aAAa;AACb,MAAM,UAAU,QAAQ,CACtB,KAA2B,EAC3B,WAAmB,EACnB,OAAa;IAEb,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE,CAAC;QAChC,MAAM,IAAI,SAAS,CAAC,6CAA6C,CAAC,CAAA;IACpE,CAAC;IAED,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC;QACzB,MAAM,IAAI,SAAS,CAAC,uDAAuD,CAAC,CAAA;IAC9E,CAAC;IAED,OAAO,UAAU;QACf,2EAA2E;QAC3E,sEAAsE;QACtE,QAAQ,EAAE,iBAAiB,CAAC,KAAK,EAAE,WAAW,CAAC,EAC/C,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,IAC9B,OAAO,EACV,CAAA;AACJ,CAAC;AAED,aAAa;AACb;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CACvB,QAA+B,EAC/B,aAAoC;IAEpC,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IAErC,IAAI,UAAU,GAAG,QAAQ,CAAC;IAC1B,IA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;QAEH,OAAO,EAAE,YAAY,EAAE,CAAC;IAC1B,CAAC;IAED,SAAS,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO;QACnC,+EAA+E;QAC/E,8EAA8E;QAC9E,8EAA8E;QAC9E,+EAA+E;QAC/E,YAAY;QACZ,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;YACpD,MAAM,WAAW,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;YAC1C,WAAW,CAAC,YAAY,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO;QACL,QAAQ;QACR,OAAO;KACR,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAS,4CAA4C,CACnD,0BAGC,EACD,IAAiB;IAEjB,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,0BAA0B,CAAC;IAChE,OAAO;QACL,QAAQ,EAAE,WAAW,CAAC,IAAI,CAAC;QAC3B,WAAW,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,CAAC;KAC7C,CAAC;AACJ,CAAC;AAED,qEAAqE;AACrE,+EAA+E;AAC/E;;;;;;GAMG;AACH,SAAS,0BAA0B,CACjC,cAAgD;IAEhD,MAAM,CAAC,OAAO,EAAE,GAAG,SAAS,CAAC,GAAG,cAAc,CAAC;IAC/C,OAAO,CAAC,GAAI,OAAe,CAAC,aAAa,EAAE,GAAG,SAAS,CAAC,CAAC;AAC3D,CAAC"}

View File

@ -12,14 +12,17 @@ export function makeQueryCacheKey(query, payload) {
export function createQuery(relativeQueryPath, entitiesUsed) {
const queryRoute = makeOperationRoute(relativeQueryPath);
const queryCacheKey = [relativeQueryPath];
const queryFn = async (queryArgs) => {
const queryFn = (async (queryArgs) => {
const serverResult = await callOperation(queryRoute, queryArgs);
// todo: The full queryCacheKey is constructed in two places, both here and
// inside the useQuery hook. See
// https://github.com/wasp-lang/wasp/issues/2017
const queryCacheKey = makeQueryCacheKey(queryFn, queryArgs);
return getActiveOptimisticUpdates(queryCacheKey).reduce((result, update) => update(result), serverResult);
};
// This assertion is necessary because, when the Input is void, we want to
// present the function as not accepting a payload (which isn't consistent
// with how it's defined).
});
return buildAndRegisterQuery(queryFn, { queryCacheKey, queryRoute, entitiesUsed });
}
// PRIVATE API (used in SDK)

View File

@ -1 +1 @@
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../../client/operations/queries/core.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACxE,OAAO,EACL,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,uBAAuB,CAAA;AAE9B,gCAAgC;AAChC,6EAA6E;AAC7E,8DAA8D;AAC9D,MAAM,UAAU,iBAAiB,CAC/B,KAA2B,EAC3B,OAAc;IAEd,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC;QAC5B,CAAC,GAAG,KAAK,CAAC,aAAa,EAAE,OAAO,CAAC;QAC/B,CAAC,CAAC,KAAK,CAAC,aAAa,CAAA;AAC3B,CAAC;AAED,6BAA6B;AAC7B,MAAM,UAAU,WAAW,CACzB,iBAAyB,EACzB,YAAsB;IAEtB,MAAM,UAAU,GAAG,kBAAkB,CAAC,iBAAiB,CAAC,CAAA;IACxD,MAAM,aAAa,GAAG,CAAC,iBAAiB,CAAC,CAAA;IAEzC,MAAM,OAAO,GAAmC,KAAK,EAAE,SAAS,EAAE,EAAE;QAClE,MAAM,YAAY,GAAG,MAAM,aAAa,CAAC,UAAU,EAAE,SAAS,CAAC,CAAA;QAC/D,2EAA2E;QAC3E,gCAAgC;QAChC,gDAAgD;QAChD,MAAM,aAAa,GAAG,iBAAiB,CAAC,OAAiC,EAAE,SAAS,CAAC,CAAA;QACrF,OAAO,0BAA0B,CAAC,aAAa,CAAC,CAAC,MAAM,CACrD,CA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M,YAAY,GAAG,MAAM,aAAa,CAAC,UAAU,EAAE,SAAS,CAAC,CAAA;QAC/D,2EAA2E;QAC3E,gCAAgC;QAChC,gDAAgD;QAChD,MAAM,aAAa,GAAG,iBAAiB,CAAC,OAAiC,EAAE,SAAS,CAAC,CAAA;QACrF,OAAO,0BAA0B,CAAC,aAAa,CAAC,CAAC,MAAM,CACrD,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAClC,YAAY,CACb,CAAA;QACD,0EAA0E;QAC1E,0EAA0E;QAC1E,0BAA0B;IAC5B,CAAC,CAAmC,CAAA;IAEpC,OAAO,qBAAqB,CAC1B,OAAO,EACP,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,CAC5C,CAAA;AACH,CAAC;AAED,4BAA4B;AAC5B,MAAM,UAAU,qBAAqB,CACnC,OAAW,EACX,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAC+B;IAExE,MAAM,KAAK,GAAG,OAA+B,CAAA;IAE7C,KAAK,CAAC,aAAa,GAAG,aAAa,CAAA;IACnC,KAAK,CAAC,KAAK,GAAG,UAAU,CAAA;IACxB,uBAAuB,CAAC,KAAK,CAAC,aAAa,EAAE,YAAY,CAAC,CAAA;IAE1D,OAAO,KAAK,CAAA;AACd,CAAC"}

View File

@ -1,4 +1,4 @@
import { type QueryFor } from './core';
import { MySpecialQuery } from 'wasp/server/operations/queries';
export declare const mySpecialQuery: QueryFor<MySpecialQuery>;
import { MySpecialQuery_ext } from 'wasp/server/operations/queries';
export declare const mySpecialQuery: QueryFor<MySpecialQuery_ext>;
export { buildAndRegisterQuery } from './core';

View File

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../client/operations/queries/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,QAAQ,CAAA;AAGnD,aAAa;AACb,MAAM,CAAC,MAAM,cAAc,GAA6B,WAAW,CACjE,6BAA6B,EAC7B,CAAC,MAAM,CAAC,CACT,CAAA;AAED,4BAA4B;AAC5B,OAAO,EAAE,qBAAqB,EAAE,MAAM,QAAQ,CAAA"}
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../client/operations/queries/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,WAAW,EAAE,MAAM,QAAQ,CAAA;AAGnD,aAAa;AACb,MAAM,CAAC,MAAM,cAAc,GAAiC,WAAW,CACrE,6BAA6B,EAC7B,CAAC,MAAM,CAAC,CACT,CAAA;AAED,4BAA4B;AAC5B,OAAO,EAAE,qBAAqB,EAAE,MAAM,QAAQ,CAAA"}

View File

@ -34,5 +34,5 @@ export type GenericBackendOperation = (args: never, context: any) => unknown;
* A supertype of all possible frontend RPC function types.
*/
export type GenericOperationRpc = (args: never) => Promise<unknown>;
type ClientOperation<Input, Output> = [Input] extends [never] ? (args?: unknown) => Promise<Output> : (args: Input) => Promise<Output>;
type ClientOperation<Input, Output> = [Input] extends [never] ? (args?: unknown) => Promise<Output> : [Input] extends [void] ? () => Promise<Output> : (args: Input) => Promise<Output>;
export {};

View File

@ -3,19 +3,19 @@ import { type Request, type Response } from 'express';
import { type ParamsDictionary as ExpressParams, type Query as ExpressQuery } from 'express-serve-static-core';
import { prisma } from 'wasp/server';
import { type AuthUser } from 'wasp/auth';
import { type _Entity } from "./taggedEntities";
import { type Payload } from "./serialization";
import { type _Entity } from './taggedEntities';
import { type Payload } from './serialization';
export * from "./taggedEntities";
export * from "./serialization";
export type Query<Entities extends _Entity[], Input extends Payload, Output extends Payload> = Operation<Entities, Input, Output>;
export type Action<Entities extends _Entity[], Input extends Payload, Output extends Payload> = Operation<Entities, Input, Output>;
export type AuthenticatedQuery<Entities extends _Entity[], Input extends Payload, Output extends Payload> = AuthenticatedOperation<Entities, Input, Output>;
export type AuthenticatedAction<Entities extends _Entity[], Input extends Payload, Output extends Payload> = AuthenticatedOperation<Entities, Input, Output>;
type AuthenticatedOperation<Entities extends _Entity[], Input extends Payload, Output extends Payload> = (args: Input, context: ContextWithUser<Entities>) => Output | Promise<Output>;
export type UnauthenticatedQueryDefinition<Entities extends _Entity[], Input extends Payload, Output extends Payload> = UnauthenticatedOperationDefinition<Entities, Input, Output>;
export type UnauthenticatedActionDefinition<Entities extends _Entity[], Input extends Payload, Output extends Payload> = UnauthenticatedOperationDefinition<Entities, Input, Output>;
export type AuthenticatedQueryDefinition<Entities extends _Entity[], Input extends Payload, Output extends Payload> = AuthenticatedOperationDefinition<Entities, Input, Output>;
export type AuthenticatedActionDefinition<Entities extends _Entity[], Input extends Payload, Output extends Payload> = AuthenticatedOperationDefinition<Entities, Input, Output>;
export type AuthenticatedOperationDefinition<Entities extends _Entity[], Input extends Payload, Output extends Payload> = (args: Input, context: ContextWithUser<Entities>) => Output | Promise<Output>;
export type AuthenticatedApi<Entities extends _Entity[], Params extends ExpressParams, ResBody, ReqBody, ReqQuery extends ExpressQuery, Locals extends Record<string, any>> = (req: Request<Params, ResBody, ReqBody, ReqQuery, Locals>, res: Response<ResBody, Locals>, context: ContextWithUser<Entities>) => void;
type Operation<Entities extends _Entity[], Input, Output> = (args: Input, context: Context<Entities>) => Output | Promise<Output>;
export type UnauthenticatedOperationDefinition<Entities extends _Entity[], Input extends Payload, Output extends Payload> = (args: Input, context: Context<Entities>) => Output | Promise<Output>;
export type Api<Entities extends _Entity[], Params extends ExpressParams, ResBody, ReqBody, ReqQuery extends ExpressQuery, Locals extends Record<string, any>> = (req: Request<Params, ResBody, ReqBody, ReqQuery, Locals>, res: Response<ResBody, Locals>, context: Context<Entities>) => void;
type EntityMap<Entities extends _Entity[]> = {
export type EntityMap<Entities extends _Entity[]> = {
[EntityName in Entities[number]["_entityName"]]: PrismaDelegate[EntityName];
};
export type PrismaDelegate = {

View File

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/_types/index.ts"],"names":[],"mappings":"AAgBA,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA"}
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/_types/index.ts"],"names":[],"mappings":"AAWA,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA"}

Some files were not shown because too many files have changed in this diff Show More