@trigger.dev/react-hooks 0.0.0-prerelease-20241119135607
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +1 -0
- package/dist/commonjs/contexts.d.ts +4 -0
- package/dist/commonjs/contexts.js +10 -0
- package/dist/commonjs/contexts.js.map +1 -0
- package/dist/commonjs/hooks/useApiClient.d.ts +33 -0
- package/dist/commonjs/hooks/useApiClient.js +40 -0
- package/dist/commonjs/hooks/useApiClient.js.map +1 -0
- package/dist/commonjs/hooks/useRealtime.d.ts +100 -0
- package/dist/commonjs/hooks/useRealtime.js +387 -0
- package/dist/commonjs/hooks/useRealtime.js.map +1 -0
- package/dist/commonjs/hooks/useRun.d.ts +22 -0
- package/dist/commonjs/hooks/useRun.js +35 -0
- package/dist/commonjs/hooks/useRun.js.map +1 -0
- package/dist/commonjs/hooks/useTaskTrigger.d.ts +101 -0
- package/dist/commonjs/hooks/useTaskTrigger.js +134 -0
- package/dist/commonjs/hooks/useTaskTrigger.js.map +1 -0
- package/dist/commonjs/index.d.ts +5 -0
- package/dist/commonjs/index.js +22 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/commonjs/utils/createContextAndHook.d.ts +15 -0
- package/dist/commonjs/utils/createContextAndHook.js +39 -0
- package/dist/commonjs/utils/createContextAndHook.js.map +1 -0
- package/dist/commonjs/utils/throttle.d.ts +6 -0
- package/dist/commonjs/utils/throttle.js +50 -0
- package/dist/commonjs/utils/throttle.js.map +1 -0
- package/dist/commonjs/utils/trigger-swr.d.ts +7 -0
- package/dist/commonjs/utils/trigger-swr.js +28 -0
- package/dist/commonjs/utils/trigger-swr.js.map +1 -0
- package/dist/esm/contexts.d.ts +4 -0
- package/dist/esm/contexts.js +5 -0
- package/dist/esm/contexts.js.map +1 -0
- package/dist/esm/hooks/useApiClient.d.ts +33 -0
- package/dist/esm/hooks/useApiClient.js +37 -0
- package/dist/esm/hooks/useApiClient.js.map +1 -0
- package/dist/esm/hooks/useRealtime.d.ts +100 -0
- package/dist/esm/hooks/useRealtime.js +381 -0
- package/dist/esm/hooks/useRealtime.js.map +1 -0
- package/dist/esm/hooks/useRun.d.ts +22 -0
- package/dist/esm/hooks/useRun.js +32 -0
- package/dist/esm/hooks/useRun.js.map +1 -0
- package/dist/esm/hooks/useTaskTrigger.d.ts +101 -0
- package/dist/esm/hooks/useTaskTrigger.js +126 -0
- package/dist/esm/hooks/useTaskTrigger.js.map +1 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/utils/createContextAndHook.d.ts +15 -0
- package/dist/esm/utils/createContextAndHook.js +31 -0
- package/dist/esm/utils/createContextAndHook.js.map +1 -0
- package/dist/esm/utils/throttle.d.ts +6 -0
- package/dist/esm/utils/throttle.js +47 -0
- package/dist/esm/utils/throttle.js.map +1 -0
- package/dist/esm/utils/trigger-swr.d.ts +7 -0
- package/dist/esm/utils/trigger-swr.js +6 -0
- package/dist/esm/utils/trigger-swr.js.map +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { makeIdempotencyKey, stringifyIO, } from "@trigger.dev/core/v3";
|
|
3
|
+
import useSWRMutation from "swr/mutation";
|
|
4
|
+
import { useApiClient } from "./useApiClient.js";
|
|
5
|
+
import { useRealtimeRun, useRealtimeRunWithStreams, } from "./useRealtime.js";
|
|
6
|
+
/**
|
|
7
|
+
* Hook to trigger a task and manage its initial execution state.
|
|
8
|
+
*
|
|
9
|
+
* @template TTask - The type of the task
|
|
10
|
+
* @param {TaskIdentifier<TTask>} id - The identifier of the task to trigger
|
|
11
|
+
* @param {UseTaskTriggerOptions} [options] - Configuration options for the task trigger
|
|
12
|
+
* @returns {TriggerInstance<TTask>} An object containing the submit function, loading state, handle, and any errors
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import type { myTask } from './path/to/task';
|
|
17
|
+
* const { submit, isLoading, handle, error } = useTaskTrigger<typeof myTask>('my-task-id');
|
|
18
|
+
*
|
|
19
|
+
* // Submit the task with payload
|
|
20
|
+
* submit({ foo: 'bar' });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export function useTaskTrigger(id, options) {
|
|
24
|
+
const apiClient = useApiClient(options);
|
|
25
|
+
async function triggerTask(id, { arg: { payload, options }, }) {
|
|
26
|
+
const payloadPacket = await stringifyIO(payload);
|
|
27
|
+
const handle = await apiClient.triggerTask(id, {
|
|
28
|
+
payload: payloadPacket.data,
|
|
29
|
+
options: {
|
|
30
|
+
queue: options?.queue,
|
|
31
|
+
concurrencyKey: options?.concurrencyKey,
|
|
32
|
+
payloadType: payloadPacket.dataType,
|
|
33
|
+
idempotencyKey: await makeIdempotencyKey(options?.idempotencyKey),
|
|
34
|
+
delay: options?.delay,
|
|
35
|
+
ttl: options?.ttl,
|
|
36
|
+
tags: options?.tags,
|
|
37
|
+
maxAttempts: options?.maxAttempts,
|
|
38
|
+
metadata: options?.metadata,
|
|
39
|
+
maxDuration: options?.maxDuration,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
return { ...handle, taskIdentifier: id };
|
|
43
|
+
}
|
|
44
|
+
const mutation = useSWRMutation(id, triggerTask);
|
|
45
|
+
return {
|
|
46
|
+
submit: (payload) => {
|
|
47
|
+
// trigger the task with the given payload
|
|
48
|
+
mutation.trigger({ payload });
|
|
49
|
+
},
|
|
50
|
+
isLoading: mutation.isMutating,
|
|
51
|
+
handle: mutation.data,
|
|
52
|
+
error: mutation.error,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Hook to trigger a task and subscribe to its realtime updates including stream data.
|
|
57
|
+
*
|
|
58
|
+
* @template TTask - The type of the task
|
|
59
|
+
* @template TStreams - The type of the streams data
|
|
60
|
+
* @param {TaskIdentifier<TTask>} id - The identifier of the task to trigger
|
|
61
|
+
* @param {UseRealtimeTaskTriggerOptions} [options] - Configuration options for the task trigger and realtime updates
|
|
62
|
+
* @returns {RealtimeTriggerInstanceWithStreams<TTask, TStreams>} An object containing the submit function, loading state,
|
|
63
|
+
* handle, run state, streams data, and error handling
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* import type { myTask } from './path/to/task';
|
|
68
|
+
* const { submit, run, streams, error } = useRealtimeTaskTriggerWithStreams<
|
|
69
|
+
* typeof myTask,
|
|
70
|
+
* { output: string }
|
|
71
|
+
* >('my-task-id');
|
|
72
|
+
*
|
|
73
|
+
* // Submit and monitor the task with streams
|
|
74
|
+
* submit({ foo: 'bar' });
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export function useRealtimeTaskTriggerWithStreams(id, options) {
|
|
78
|
+
const triggerInstance = useTaskTrigger(id, options);
|
|
79
|
+
const realtimeInstance = useRealtimeRunWithStreams(triggerInstance.handle?.id, {
|
|
80
|
+
...options,
|
|
81
|
+
id: triggerInstance.handle?.id,
|
|
82
|
+
accessToken: triggerInstance.handle?.publicAccessToken ?? options?.accessToken,
|
|
83
|
+
});
|
|
84
|
+
return {
|
|
85
|
+
...realtimeInstance,
|
|
86
|
+
...triggerInstance,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Hook to trigger a task and subscribe to its realtime updates.
|
|
91
|
+
*
|
|
92
|
+
* @template TTask - The type of the task
|
|
93
|
+
* @param {TaskIdentifier<TTask>} id - The identifier of the task to trigger
|
|
94
|
+
* @param {UseRealtimeTaskTriggerOptions} [options] - Configuration options for the task trigger and realtime updates
|
|
95
|
+
* @returns {RealtimeTriggerInstance<TTask>} An object containing the submit function, loading state,
|
|
96
|
+
* handle, run state, and error handling
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* import type { myTask } from './path/to/task';
|
|
101
|
+
* const { submit, run, error, stop } = useRealtimeTaskTrigger<typeof myTask>('my-task-id');
|
|
102
|
+
*
|
|
103
|
+
* // Submit and monitor the task
|
|
104
|
+
* submit({ foo: 'bar' });
|
|
105
|
+
*
|
|
106
|
+
* // Stop monitoring when needed
|
|
107
|
+
* stop();
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export function useRealtimeTaskTrigger(id, options) {
|
|
111
|
+
const triggerInstance = useTaskTrigger(id, options);
|
|
112
|
+
const realtimeInstance = useRealtimeRun(triggerInstance.handle?.id, {
|
|
113
|
+
...options,
|
|
114
|
+
id: triggerInstance.handle?.id,
|
|
115
|
+
accessToken: triggerInstance.handle?.publicAccessToken ?? options?.accessToken,
|
|
116
|
+
});
|
|
117
|
+
return {
|
|
118
|
+
submit: triggerInstance.submit,
|
|
119
|
+
isLoading: triggerInstance.isLoading,
|
|
120
|
+
handle: triggerInstance.handle,
|
|
121
|
+
run: realtimeInstance.run,
|
|
122
|
+
error: realtimeInstance.error ?? triggerInstance.error,
|
|
123
|
+
stop: realtimeInstance.stop,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=useTaskTrigger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTaskTrigger.js","sourceRoot":"","sources":["../../../src/hooks/useTaskTrigger.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAKL,kBAAkB,EAElB,WAAW,GAEZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,cAAc,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAuB,MAAM,mBAAmB,CAAC;AACtE,OAAO,EACL,cAAc,EAEd,yBAAyB,GAE1B,MAAM,kBAAkB,CAAC;AAoB1B;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,cAAc,CAC5B,EAAyB,EACzB,OAA+B;IAE/B,MAAM,SAAS,GAAG,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AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export declare function assertContextExists(contextVal: unknown, msgOrCtx: string | React.Context<any>): asserts contextVal;
|
|
3
|
+
type Options = {
|
|
4
|
+
assertCtxFn?: (v: unknown, msg: string) => void;
|
|
5
|
+
};
|
|
6
|
+
type ContextOf<T> = React.Context<T | undefined>;
|
|
7
|
+
type UseCtxFn<T> = () => T;
|
|
8
|
+
/**
|
|
9
|
+
* Creates and returns a Context and two hooks that return the context value.
|
|
10
|
+
* The Context type is derived from the type passed in by the user.
|
|
11
|
+
* The first hook returned guarantees that the context exists so the returned value is always CtxValue
|
|
12
|
+
* The second hook makes no guarantees, so the returned value can be CtxValue | undefined
|
|
13
|
+
*/
|
|
14
|
+
export declare const createContextAndHook: <CtxVal>(displayName: string, options?: Options) => [ContextOf<CtxVal>, UseCtxFn<CtxVal>, UseCtxFn<CtxVal | Partial<CtxVal>>];
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import React from "react";
|
|
3
|
+
export function assertContextExists(contextVal, msgOrCtx) {
|
|
4
|
+
if (!contextVal) {
|
|
5
|
+
throw typeof msgOrCtx === "string"
|
|
6
|
+
? new Error(msgOrCtx)
|
|
7
|
+
: new Error(`${msgOrCtx.displayName} not found`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Creates and returns a Context and two hooks that return the context value.
|
|
12
|
+
* The Context type is derived from the type passed in by the user.
|
|
13
|
+
* The first hook returned guarantees that the context exists so the returned value is always CtxValue
|
|
14
|
+
* The second hook makes no guarantees, so the returned value can be CtxValue | undefined
|
|
15
|
+
*/
|
|
16
|
+
export const createContextAndHook = (displayName, options) => {
|
|
17
|
+
const { assertCtxFn = assertContextExists } = options || {};
|
|
18
|
+
const Ctx = React.createContext(undefined);
|
|
19
|
+
Ctx.displayName = displayName;
|
|
20
|
+
const useCtx = () => {
|
|
21
|
+
const ctx = React.useContext(Ctx);
|
|
22
|
+
assertCtxFn(ctx, `${displayName} not found`);
|
|
23
|
+
return ctx;
|
|
24
|
+
};
|
|
25
|
+
const useCtxWithoutGuarantee = () => {
|
|
26
|
+
const ctx = React.useContext(Ctx);
|
|
27
|
+
return ctx ? ctx : {};
|
|
28
|
+
};
|
|
29
|
+
return [Ctx, useCtx, useCtxWithoutGuarantee];
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=createContextAndHook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createContextAndHook.js","sourceRoot":"","sources":["../../../src/utils/createContextAndHook.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,UAAU,mBAAmB,CACjC,UAAmB,EACnB,QAAqC;IAErC,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,OAAO,QAAQ,KAAK,QAAQ;YAChC,CAAC,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC;YACrB,CAAC,CAAC,IAAI,KAAK,CAAC,GAAG,QAAQ,CAAC,WAAW,YAAY,CAAC,CAAC;IACrD,CAAC;AACH,CAAC;AAMD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,WAAmB,EACnB,OAAiB,EAC0D,EAAE;IAC7E,MAAM,EAAE,WAAW,GAAG,mBAAmB,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAC5D,MAAM,GAAG,GAAG,KAAK,CAAC,aAAa,CAAqB,SAAS,CAAC,CAAC;IAC/D,GAAG,CAAC,WAAW,GAAG,WAAW,CAAC;IAE9B,MAAM,MAAM,GAAG,GAAG,EAAE;QAClB,MAAM,GAAG,GAAG,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAClC,WAAW,CAAC,GAAG,EAAE,GAAG,WAAW,YAAY,CAAC,CAAC;QAC7C,OAAO,GAAa,CAAC;IACvB,CAAC,CAAC;IAEF,MAAM,sBAAsB,GAAG,GAAG,EAAE;QAClC,MAAM,GAAG,GAAG,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAClC,OAAO,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IACxB,CAAC,CAAC;IAEF,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,sBAAsB,CAAC,CAAC;AAC/C,CAAC,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export function createThrottledQueue(onFlush, throttleInMs) {
|
|
2
|
+
let queue = [];
|
|
3
|
+
let lastFlushTime = 0;
|
|
4
|
+
let flushPromise = null;
|
|
5
|
+
const scheduleFlush = async () => {
|
|
6
|
+
// If no throttle specified or there's already a flush in progress, return
|
|
7
|
+
if (!throttleInMs) {
|
|
8
|
+
// Immediately flush when no throttling is specified
|
|
9
|
+
const itemsToFlush = [...queue];
|
|
10
|
+
queue = [];
|
|
11
|
+
await onFlush(itemsToFlush);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (queue.length === 0 || flushPromise)
|
|
15
|
+
return;
|
|
16
|
+
const now = Date.now();
|
|
17
|
+
const timeUntilNextFlush = Math.max(0, lastFlushTime + throttleInMs - now);
|
|
18
|
+
if (timeUntilNextFlush === 0) {
|
|
19
|
+
const itemsToFlush = [...queue];
|
|
20
|
+
queue = [];
|
|
21
|
+
lastFlushTime = now;
|
|
22
|
+
flushPromise = onFlush(itemsToFlush).finally(() => {
|
|
23
|
+
flushPromise = null;
|
|
24
|
+
// Check if more items accumulated during flush
|
|
25
|
+
scheduleFlush();
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
setTimeout(scheduleFlush, timeUntilNextFlush);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
add: (item) => {
|
|
34
|
+
queue.push(item);
|
|
35
|
+
scheduleFlush();
|
|
36
|
+
},
|
|
37
|
+
flush: async () => {
|
|
38
|
+
if (queue.length === 0)
|
|
39
|
+
return;
|
|
40
|
+
const itemsToFlush = [...queue];
|
|
41
|
+
queue = [];
|
|
42
|
+
await onFlush(itemsToFlush);
|
|
43
|
+
},
|
|
44
|
+
isEmpty: () => queue.length === 0,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=throttle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"throttle.js","sourceRoot":"","sources":["../../../src/utils/throttle.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,oBAAoB,CAClC,OAAsC,EACtC,YAAqB;IAErB,IAAI,KAAK,GAAQ,EAAE,CAAC;IACpB,IAAI,aAAa,GAAG,CAAC,CAAC;IACtB,IAAI,YAAY,GAAyB,IAAI,CAAC;IAE9C,MAAM,aAAa,GAAG,KAAK,IAAI,EAAE;QAC/B,0EAA0E;QAC1E,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,oDAAoD;YACpD,MAAM,YAAY,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;YAChC,KAAK,GAAG,EAAE,CAAC;YACX,MAAM,OAAO,CAAC,YAAY,CAAC,CAAC;YAC5B,OAAO;QACT,CAAC;QAED,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,YAAY;YAAE,OAAO;QAE/C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,kBAAkB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,aAAa,GAAG,YAAY,GAAG,GAAG,CAAC,CAAC;QAE3E,IAAI,kBAAkB,KAAK,CAAC,EAAE,CAAC;YAC7B,MAAM,YAAY,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;YAChC,KAAK,GAAG,EAAE,CAAC;YACX,aAAa,GAAG,GAAG,CAAC;YACpB,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE;gBAChD,YAAY,GAAG,IAAI,CAAC;gBACpB,+CAA+C;gBAC/C,aAAa,EAAE,CAAC;YAClB,CAAC,CAAC,CAAC;QACL,CAAC;aAAM,CAAC;YACN,UAAU,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAC;QAChD,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,GAAG,EAAE,CAAC,IAAO,EAAE,EAAE;YACf,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjB,aAAa,EAAE,CAAC;QAClB,CAAC;QACD,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO;YAC/B,MAAM,YAAY,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;YAChC,KAAK,GAAG,EAAE,CAAC;YACX,MAAM,OAAO,CAAC,YAAY,CAAC,CAAC;QAC9B,CAAC;QACD,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC;KAClC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trigger-swr.js","sourceRoot":"","sources":["../../../src/utils/trigger-swr.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,yCAAyC;AACzC,cAAc,KAAK,CAAC;AACpB,yCAAyC;AACzC,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@trigger.dev/react-hooks",
|
|
3
|
+
"version": "0.0.0-prerelease-20241119135607",
|
|
4
|
+
"description": "trigger.dev react hooks",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/triggerdotdev/trigger.dev",
|
|
12
|
+
"directory": "packages/react-hooks"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"tshy": {
|
|
19
|
+
"selfLink": false,
|
|
20
|
+
"main": true,
|
|
21
|
+
"module": true,
|
|
22
|
+
"project": "./tsconfig.json",
|
|
23
|
+
"exports": {
|
|
24
|
+
"./package.json": "./package.json",
|
|
25
|
+
".": "./src/index.ts"
|
|
26
|
+
},
|
|
27
|
+
"sourceDialects": [
|
|
28
|
+
"@triggerdotdev/source"
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@trigger.dev/core": "0.0.0-prerelease-20241119135607",
|
|
33
|
+
"swr": "^2.2.5"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@arethetypeswrong/cli": "^0.15.4",
|
|
37
|
+
"@types/node": "^20.14.14",
|
|
38
|
+
"@types/react": "*",
|
|
39
|
+
"@types/react-dom": "*",
|
|
40
|
+
"rimraf": "^3.0.2",
|
|
41
|
+
"tshy": "^3.0.2",
|
|
42
|
+
"tsx": "4.17.0",
|
|
43
|
+
"typescript": "^5.5.4"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"react": ">=18 || >=19.0.0-beta",
|
|
47
|
+
"react-dom": ">=18 || >=19.0.0-beta"
|
|
48
|
+
},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=18.20.0"
|
|
51
|
+
},
|
|
52
|
+
"exports": {
|
|
53
|
+
"./package.json": "./package.json",
|
|
54
|
+
".": {
|
|
55
|
+
"import": {
|
|
56
|
+
"@triggerdotdev/source": "./src/index.ts",
|
|
57
|
+
"types": "./dist/esm/index.d.ts",
|
|
58
|
+
"default": "./dist/esm/index.js"
|
|
59
|
+
},
|
|
60
|
+
"require": {
|
|
61
|
+
"types": "./dist/commonjs/index.d.ts",
|
|
62
|
+
"default": "./dist/commonjs/index.js"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"main": "./dist/commonjs/index.js",
|
|
67
|
+
"types": "./dist/commonjs/index.d.ts",
|
|
68
|
+
"module": "./dist/esm/index.js",
|
|
69
|
+
"scripts": {
|
|
70
|
+
"clean": "rimraf dist",
|
|
71
|
+
"build": "tshy && pnpm run update-version",
|
|
72
|
+
"dev": "tshy --watch",
|
|
73
|
+
"typecheck": "tsc --noEmit",
|
|
74
|
+
"update-version": "tsx ../../scripts/updateVersion.ts",
|
|
75
|
+
"check-exports": "attw --pack ."
|
|
76
|
+
}
|
|
77
|
+
}
|