@nice-code/action 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/{ActionDevtoolsCore-yfJ9tkvl.js → ActionDevtoolsCore-9PsnscvK.mjs} +2 -2
- package/build/ActionDevtoolsCore-9PsnscvK.mjs.map +1 -0
- package/build/{ActionDevtoolsCore-B4s6aGvI.d.ts → ActionDevtoolsCore-CCRLYASa.d.cts} +2 -2
- package/build/{ActionDevtoolsCore-Pg7ERO3L.d.ts → ActionDevtoolsCore-CYGD2o6C.d.mts} +2 -2
- package/build/{ActionDevtoolsCore-BLeY_N-3.js → ActionDevtoolsCore-DtgXwPBZ.cjs} +2 -2
- package/build/ActionDevtoolsCore-DtgXwPBZ.cjs.map +1 -0
- package/build/{ActionPayload.types-BN-rXFBK.d.ts → ActionPayload.types-BN-rXFBK.d.cts} +1 -1
- package/build/{ActionPayload.types-D28ELKXC.d.ts → ActionPayload.types-D28ELKXC.d.mts} +1 -1
- package/build/{RunningAction.types-C176rqHG.js → RunningAction.types-C176rqHG.mjs} +1 -1
- package/build/RunningAction.types-C176rqHG.mjs.map +1 -0
- package/build/{RunningAction.types-DjCX1xp5.js → RunningAction.types-DjCX1xp5.cjs} +1 -1
- package/build/RunningAction.types-DjCX1xp5.cjs.map +1 -0
- package/build/devtools/browser/index.cjs +3886 -0
- package/build/devtools/browser/index.cjs.map +1 -0
- package/build/devtools/browser/{index.d.ts → index.d.cts} +2 -2
- package/build/devtools/browser/index.d.mts +17 -0
- package/build/devtools/browser/{index.js → index.mjs} +2 -2
- package/build/devtools/browser/index.mjs.map +1 -0
- package/build/devtools/server/index.cjs +108 -0
- package/build/devtools/server/index.cjs.map +1 -0
- package/build/devtools/server/{index.d.ts → index.d.cts} +2 -2
- package/build/devtools/server/index.d.mts +35 -0
- package/build/devtools/server/{index.js → index.mjs} +3 -3
- package/build/devtools/server/index.mjs.map +1 -0
- package/build/index.cjs +4045 -0
- package/build/index.cjs.map +1 -0
- package/build/{index.d.ts → index.d.cts} +1 -1
- package/build/index.d.mts +2 -0
- package/build/{index.js → index.mjs} +2 -2
- package/build/index.mjs.map +1 -0
- package/build/react-query/index.cjs +70 -0
- package/build/react-query/index.cjs.map +1 -0
- package/build/react-query/{index.d.ts → index.d.cts} +2 -2
- package/build/react-query/index.d.mts +17 -0
- package/build/react-query/{index.js → index.mjs} +1 -1
- package/build/react-query/index.mjs.map +1 -0
- package/package.json +39 -16
- package/build/ActionDevtoolsCore-BLeY_N-3.js.map +0 -1
- package/build/ActionDevtoolsCore-yfJ9tkvl.js.map +0 -1
- package/build/RunningAction.types-C176rqHG.js.map +0 -1
- package/build/RunningAction.types-DjCX1xp5.js.map +0 -1
- package/build/devtools/browser/index.js.map +0 -1
- package/build/devtools/server/index.js.map +0 -1
- package/build/index.js.map +0 -1
- package/build/react-query/index.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/react-query/hooks/useActionMutation.ts","../../src/react-query/hooks/useActionQuery.ts"],"sourcesContent":["import {\r\n type UseMutationOptions,\r\n type UseMutationResult,\r\n useMutation,\r\n} from \"@tanstack/react-query\";\r\nimport { useRef } from \"react\";\r\nimport type { ActionCore } from \"../../ActionDefinition/Action/Core/ActionCore\";\r\nimport type {\r\n IActionDomain,\r\n TInferInputFromSchema,\r\n TInferOutputFromSchema,\r\n} from \"../../ActionDefinition/Domain/ActionDomain.types\";\r\nimport type { ActionSchema, TInferActionError } from \"../../ActionDefinition/Schema/ActionSchema\";\r\n\r\n/** When an action has no input schema (Input = never), use void so mutate() needs no arguments. */\r\nexport type TActionMutationVars<SCH extends ActionSchema<any, any, any>> = [\r\n TInferInputFromSchema<SCH>[\"Input\"],\r\n] extends [never]\r\n ? void\r\n : TInferInputFromSchema<SCH>[\"Input\"];\r\n\r\nexport type TUseNiceMutationOptions<\r\n DOM extends IActionDomain,\r\n ID extends keyof DOM[\"actionSchema\"] & string,\r\n SCH extends DOM[\"actionSchema\"][ID] = DOM[\"actionSchema\"][ID],\r\n TContext = unknown,\r\n> = Omit<\r\n UseMutationOptions<\r\n TInferOutputFromSchema<SCH>[\"Output\"],\r\n TInferActionError<SCH>,\r\n TActionMutationVars<SCH>,\r\n TContext\r\n >,\r\n \"mutationFn\"\r\n>;\r\n\r\nexport function useActionMutation<\r\n DOM extends IActionDomain,\r\n ID extends keyof DOM[\"actionSchema\"] & string,\r\n SCH extends DOM[\"actionSchema\"][ID],\r\n TContext = unknown,\r\n>(\r\n action: ActionCore<DOM, ID>,\r\n options?: TUseNiceMutationOptions<DOM, ID, SCH, TContext>,\r\n): UseMutationResult<\r\n TInferOutputFromSchema<SCH>[\"Output\"],\r\n TInferActionError<SCH>,\r\n TActionMutationVars<SCH>,\r\n TContext\r\n> {\r\n const mutationOptions = options ?? {};\r\n\r\n // Side-channel for the call site: mutate() writes it synchronously, mutationFn reads it.\r\n // React Query calls mutationFn synchronously within mutate(), so the ref is always fresh.\r\n const callSiteRef = useRef<string | undefined>(undefined);\r\n\r\n const result = useMutation({\r\n mutationFn: (input: TActionMutationVars<SCH>) => {\r\n const req = action.request(input as unknown as TInferInputFromSchema<SCH>[\"Input\"]);\r\n req._callSite = callSiteRef.current;\r\n callSiteRef.current = undefined;\r\n return req.runToOutput();\r\n },\r\n ...mutationOptions,\r\n });\r\n\r\n // Wrap mutate/mutateAsync so the call site is captured at the user's invocation point.\r\n // By the time mutationFn runs inside React Query's scheduler the user's frames are gone.\r\n return {\r\n ...result,\r\n mutate: (...args: Parameters<typeof result.mutate>) => {\r\n callSiteRef.current = new Error().stack;\r\n return result.mutate(...args);\r\n },\r\n mutateAsync: (...args: Parameters<typeof result.mutateAsync>) => {\r\n callSiteRef.current = new Error().stack;\r\n return result.mutateAsync(...args);\r\n },\r\n };\r\n}\r\n","import {\n type QueryKey,\n type UseQueryOptions,\n type UseQueryResult,\n useQuery,\n} from \"@tanstack/react-query\";\nimport { useRef } from \"react\";\nimport type { ActionCore } from \"../../ActionDefinition/Action/Core/ActionCore\";\nimport type {\n IActionDomain,\n TInferInputFromSchema,\n TInferOutputFromSchema,\n} from \"../../ActionDefinition/Domain/ActionDomain.types\";\nimport type { TInferActionError } from \"../../ActionDefinition/Schema/ActionSchema\";\n\nexport function actionQueryKey<\n DOM extends IActionDomain,\n ID extends keyof DOM[\"actionSchema\"] & string,\n>(action: ActionCore<DOM, ID>): readonly [\"nice-action\", DOM[\"domain\"], DOM[\"allDomains\"], ID];\n\nexport function actionQueryKey<\n DOM extends IActionDomain,\n ID extends keyof DOM[\"actionSchema\"] & string,\n>(\n action: ActionCore<DOM, ID>,\n input: TInferInputFromSchema<DOM[\"actionSchema\"][ID]>[\"Input\"],\n): readonly [\n \"nice-action\",\n DOM[\"domain\"],\n DOM[\"allDomains\"],\n ID,\n TInferInputFromSchema<DOM[\"actionSchema\"][ID]>[\"Input\"],\n];\n\nexport function actionQueryKey(action: ActionCore<any, any>, input?: unknown): QueryKey {\n if (input === undefined) {\n return [\"nice-action\", action.domain, action.allDomains, action.id] as const;\n }\n\n return [\"nice-action\", action.domain, action.allDomains, action.id, input] as const;\n}\n\nexport type TUseActionQueryOptions<\n DOM extends IActionDomain,\n ID extends keyof DOM[\"actionSchema\"] & string,\n SCH extends DOM[\"actionSchema\"][ID] = DOM[\"actionSchema\"][ID],\n TSelect = TInferOutputFromSchema<SCH>[\"Output\"],\n> = Omit<\n UseQueryOptions<TInferOutputFromSchema<SCH>[\"Output\"], TInferActionError<SCH>, TSelect, QueryKey>,\n \"queryKey\" | \"queryFn\"\n>;\n\nexport function useActionQuery<\n DOM extends IActionDomain,\n ID extends keyof DOM[\"actionSchema\"] & string,\n SCH extends DOM[\"actionSchema\"][ID],\n TSelect = TInferOutputFromSchema<SCH>[\"Output\"],\n>(\n action: ActionCore<DOM, ID>,\n ...args: [TInferInputFromSchema<SCH>[\"Input\"]] extends [never]\n ? [options?: TUseActionQueryOptions<DOM, ID, SCH, TSelect>]\n : [\n input: TInferInputFromSchema<SCH>[\"Input\"] | null | undefined,\n options?: TUseActionQueryOptions<DOM, ID, SCH, TSelect>,\n ]\n): UseQueryResult<TSelect, TInferActionError<SCH>> {\n const hasInputSchema = action.schema.inputSchema != null;\n\n let input: TInferInputFromSchema<SCH>[\"Input\"] | null | undefined;\n let options: TUseActionQueryOptions<DOM, ID, SCH, TSelect> | undefined;\n\n if (hasInputSchema) {\n [input, options] = args as [\n TInferInputFromSchema<SCH>[\"Input\"] | null | undefined,\n TUseActionQueryOptions<DOM, ID, SCH, TSelect>?,\n ];\n } else {\n [options] = args as [TUseActionQueryOptions<DOM, ID, SCH, TSelect>?];\n }\n\n const { enabled, ...queryOptions } = options ?? {};\n\n // Capture the call site synchronously here — the user's component frame is on the\n // stack now. By the time queryFn runs inside React Query's scheduler it's gone.\n const callSiteRef = useRef(new Error().stack);\n\n return useQuery({\n queryKey: input != null ? actionQueryKey(action, input) : actionQueryKey(action),\n queryFn: () => {\n const req = (action.request as (input: any) => any)(input);\n req._callSite = callSiteRef.current;\n return req.runToOutput();\n },\n enabled: hasInputSchema ? input != null && (enabled ?? true) : (enabled ?? true),\n ...queryOptions,\n } as UseQueryOptions<TInferOutputFromSchema<SCH>[\"Output\"], TInferActionError<SCH>, TSelect>);\n}\n"],"mappings":";;;AAoCA,SAAgB,kBAMd,QACA,SAMA;CACA,MAAM,kBAAkB,WAAW,CAAC;CAIpC,MAAM,cAAc,OAA2B,KAAA,CAAS;CAExD,MAAM,SAAS,YAAY;EACzB,aAAa,UAAoC;GAC/C,MAAM,MAAM,OAAO,QAAQ,KAAuD;GAClF,IAAI,YAAY,YAAY;GAC5B,YAAY,UAAU,KAAA;GACtB,OAAO,IAAI,YAAY;EACzB;EACA,GAAG;CACL,CAAC;CAID,OAAO;EACL,GAAG;EACH,SAAS,GAAG,SAA2C;GACrD,YAAY,2BAAU,IAAI,MAAM,EAAA,CAAE;GAClC,OAAO,OAAO,OAAO,GAAG,IAAI;EAC9B;EACA,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