Comparing version 2.4.2-pr-294.6 to 2.4.2-pr-294.7
@@ -7,7 +7,7 @@ import { z } from "zod"; | ||
}, "strip", z.ZodTypeAny, { | ||
status: number; | ||
error: string; | ||
}, { | ||
status: number; | ||
}, { | ||
error: string; | ||
status: number; | ||
}>; | ||
@@ -14,0 +14,0 @@ export type ErrorResponse = z.infer<typeof ErrorSchema>; |
# inngest | ||
## 2.5.2 | ||
### Patch Changes | ||
- [#305](https://github.com/inngest/inngest-js/pull/305) [`10220af`](https://github.com/inngest/inngest-js/commit/10220af5b666eb1f09cbb47d252edde8c78b5a48) Thanks [@jpwilliams](https://github.com/jpwilliams)! - Always attempt accessing the dev server if the `INNGEST_DEVSERVER_URL` environment variable is specified | ||
This helps some situations where a user may want to run integration tests against a deployed or otherwise production build, using the Inngest Dev Server to do so. | ||
## 2.5.1 | ||
@@ -4,0 +12,0 @@ |
@@ -23,2 +23,31 @@ import { type Simplify } from "type-fest"; | ||
/** | ||
* A helper type that ensures users cannot declare a literal Zod schema with | ||
* an empty string as the event name. | ||
* | ||
* @public | ||
*/ | ||
export type ExcludeEmptyZodLiterals<T> = T extends LiteralZodEventSchemas ? { | ||
[I in keyof T]: T[I] extends z.ZodObject<infer U extends z.ZodRawShape> ? U extends { | ||
name: z.ZodLiteral<"">; | ||
} ? "ERROR: Empty event names are now allowed." : T[I] : never; | ||
} : T; | ||
/** | ||
* A literal Zod schema, which is a Zod schema that has a literal string as the | ||
* event name. This can be used to create correct Zod schemas outside of the | ||
* `EventSchemas` class. | ||
* | ||
* @public | ||
*/ | ||
export type LiteralZodEventSchema = z.ZodObject<{ | ||
name: z.ZodLiteral<string>; | ||
data: z.AnyZodObject | z.ZodAny; | ||
user?: z.AnyZodObject | z.ZodAny; | ||
}>; | ||
/** | ||
* An array of literal zod event schemas. | ||
* | ||
* @public | ||
*/ | ||
export type LiteralZodEventSchemas = LiteralZodEventSchema[]; | ||
/** | ||
* A helper type that declares a standardised custom part of the event schema, | ||
@@ -34,2 +63,49 @@ * defined using Zod. | ||
/** | ||
* A helper type that takes a union of Zod schemas and extracts the literal | ||
* matching event from the given schemas. Required when picking out types from | ||
* a union that require inference to work. | ||
* | ||
* @public | ||
*/ | ||
export type PickLiterals<T> = { | ||
[K in keyof T]: Extract<T[K], { | ||
name: z.ZodLiteral<K>; | ||
}>; | ||
}; | ||
/** | ||
* A helper type to extract the name from a given literal Zod schema. | ||
* | ||
* @public | ||
*/ | ||
export type GetName<T> = T extends z.ZodObject<infer U extends z.ZodRawShape> ? U extends { | ||
name: z.ZodLiteral<infer S extends string>; | ||
} ? S : never : never; | ||
/** | ||
* Given an input T, infer the shape of the Zod schema if that input is a Zod | ||
* object. | ||
* | ||
* @public | ||
*/ | ||
export type InferZodShape<T> = T extends z.AnyZodObject ? T["shape"] : never; | ||
/** | ||
* Given a set of literal Zod schemas, convert them into a record of Zod schemas | ||
* with the literal name as the key. | ||
* | ||
* @public | ||
*/ | ||
export type LiteralToRecordZodSchemas<T> = PickLiterals<T extends LiteralZodEventSchemas ? { | ||
[I in keyof T as GetName<T[I]>]: InferZodShape<T[I]>; | ||
} : T extends ZodEventSchemas ? T : never>; | ||
/** | ||
* Given a set of Zod schemas in a record format, convert them into a standard | ||
* event schema format. | ||
* | ||
* @public | ||
*/ | ||
export type ZodToStandardSchema<T extends ZodEventSchemas> = { | ||
[EventName in keyof T & string]: { | ||
[Key in keyof T[EventName] & string]: T[EventName][Key] extends z.ZodTypeAny ? z.infer<T[EventName][Key]> : T[EventName][Key]; | ||
}; | ||
}; | ||
/** | ||
* A helper type to convert input schemas into the format expected by the | ||
@@ -161,4 +237,4 @@ * `EventSchemas` class, which ensures that each event contains all pieces | ||
*/ | ||
fromZod<T extends ZodEventSchemas>(schemas: T): EventSchemas<Combine<S, { [EventName in keyof T & string]: { [Key in keyof T[EventName] & string]: T[EventName][Key] extends z.ZodTypeAny ? z.TypeOf<T[EventName][Key]> : T[EventName][Key]; }; }>>; | ||
fromZod<T extends ZodEventSchemas | LiteralZodEventSchemas>(schemas: ExcludeEmptyZodLiterals<T>): EventSchemas<Combine<S, ZodToStandardSchema<T extends ZodEventSchemas ? T : PickLiterals<T extends LiteralZodEventSchemas ? T extends infer T_1 extends LiteralZodEventSchemas ? { [I in keyof T_1 as GetName<T[I]>]: InferZodShape<T[I]>; } : never : T extends ZodEventSchemas ? T : never>>>>; | ||
} | ||
//# sourceMappingURL=EventSchemas.d.ts.map |
@@ -106,4 +106,5 @@ "use strict"; | ||
*/ | ||
fromZod( | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
fromZod(schemas) { | ||
schemas) { | ||
return new EventSchemas(); | ||
@@ -110,0 +111,0 @@ } |
@@ -343,4 +343,9 @@ "use strict"; | ||
this._isProd = (_b = actions.isProduction) !== null && _b !== void 0 ? _b : (0, env_1.isProd)(env); | ||
// If we're in production always skip. | ||
this._skipDevServer = (_c = this._isProd) !== null && _c !== void 0 ? _c : (0, env_1.skipDevServer)(env); | ||
/** | ||
* If we've been explicitly passed an Inngest dev sever URL, assume that | ||
* we shouldn't skip the dev server. | ||
*/ | ||
this._skipDevServer = (0, env_1.devServerHost)(env) | ||
? false | ||
: (_c = this._isProd) !== null && _c !== void 0 ? _c : (0, env_1.skipDevServer)(env); | ||
try { | ||
@@ -347,0 +352,0 @@ const runRes = await actions.run(); |
@@ -75,3 +75,5 @@ "use strict"; | ||
} | ||
const opId = matchOp(...args); | ||
const [stepOptionsOrId, ...remainingArgs] = args; | ||
const stepOptions = getStepOptions(stepOptionsOrId); | ||
const opId = matchOp(stepOptions, ...remainingArgs); | ||
// TODO Need indexing? | ||
@@ -105,7 +107,7 @@ if (state.steps[opId.id]) { | ||
}; | ||
const getStepIdFromOptions = (options) => { | ||
const getStepOptions = (options) => { | ||
if (typeof options === "string") { | ||
return options; | ||
return { id: options }; | ||
} | ||
return options.id; | ||
return options; | ||
}; | ||
@@ -144,7 +146,8 @@ /** | ||
*/ | ||
sendEvent: createTool((idOrOptions) => { | ||
sendEvent: createTool(({ id, name }) => { | ||
return { | ||
id: getStepIdFromOptions(idOrOptions), | ||
id, | ||
op: types_1.StepOpCode.StepPlanned, | ||
name: "sendEvent", | ||
displayName: name, | ||
}; | ||
@@ -166,3 +169,3 @@ }, { | ||
*/ | ||
waitForEvent: createTool((idOrOptions, | ||
waitForEvent: createTool(({ id, name }, | ||
/** | ||
@@ -189,6 +192,7 @@ * The event name to wait for. | ||
return { | ||
id: getStepIdFromOptions(idOrOptions), | ||
id, | ||
op: types_1.StepOpCode.WaitForEvent, | ||
name: event, | ||
opts: matchOpts, | ||
displayName: name, | ||
}; | ||
@@ -208,12 +212,10 @@ }), | ||
*/ | ||
run: createTool((idOrOptions) => { | ||
const id = getStepIdFromOptions(idOrOptions); | ||
run: createTool(({ id, name }) => { | ||
return { | ||
id, | ||
op: types_1.StepOpCode.StepPlanned, | ||
// TODO Bad idea to default the name to the ID? Might be confusing | ||
// what the user can safely change. | ||
name: id, | ||
displayName: name, | ||
}; | ||
}, { fn: (idOrOptions, fn) => fn() }), | ||
}, { fn: (stepOptions, fn) => fn() }), | ||
/** | ||
@@ -229,3 +231,3 @@ * Wait a specified amount of time before continuing. | ||
*/ | ||
sleep: createTool((idOrOptions, time) => { | ||
sleep: createTool(({ id, name }, time) => { | ||
/** | ||
@@ -236,5 +238,6 @@ * The presence of this operation in the returned stack indicates that the | ||
return { | ||
id: getStepIdFromOptions(idOrOptions), | ||
id, | ||
op: types_1.StepOpCode.Sleep, | ||
name: (0, strings_1.timeStr)(time), | ||
displayName: name, | ||
}; | ||
@@ -248,3 +251,3 @@ }), | ||
*/ | ||
sleepUntil: createTool((idOrOptions, time) => { | ||
sleepUntil: createTool(({ id, name }, time) => { | ||
const date = typeof time === "string" ? new Date(time) : time; | ||
@@ -257,5 +260,6 @@ /** | ||
return { | ||
id: getStepIdFromOptions(idOrOptions), | ||
id, | ||
op: types_1.StepOpCode.Sleep, | ||
name: date.toISOString(), | ||
displayName: name, | ||
}; | ||
@@ -262,0 +266,0 @@ } |
@@ -11,3 +11,3 @@ import { type Inngest } from "../components/Inngest"; | ||
*/ | ||
export declare const devServerHost: () => string | undefined; | ||
export declare const devServerHost: (env?: Record<string, unknown>) => string | undefined; | ||
/** | ||
@@ -14,0 +14,0 @@ * Returns `true` if we're running in production or on a platform, based off of |
@@ -19,3 +19,3 @@ "use strict"; | ||
*/ | ||
const devServerHost = () => { | ||
const devServerHost = (env = (0, exports.allProcessEnv)()) => { | ||
// devServerKeys are the env keys we search for to discover the dev server | ||
@@ -30,5 +30,5 @@ // URL. This includes the standard key first, then includes prefixed keys | ||
const values = [ | ||
(0, exports.processEnv)(consts_1.envKeys.DevServerUrl), | ||
(0, exports.processEnv)("REACT_APP_INNGEST_DEVSERVER_URL"), | ||
(0, exports.processEnv)("NEXT_PUBLIC_INNGEST_DEVSERVER_URL"), | ||
env[consts_1.envKeys.DevServerUrl], | ||
env["REACT_APP_INNGEST_DEVSERVER_URL"], | ||
env["NEXT_PUBLIC_INNGEST_DEVSERVER_URL"], | ||
]; | ||
@@ -35,0 +35,0 @@ return values.find((a) => !!a); |
@@ -153,3 +153,8 @@ import { type Simplify } from "type-fest"; | ||
export type Either<A, B> = Partial<A> & Partial<B> & (A | B); | ||
/** | ||
* Given a function `T`, return the parameters of that function, except for the | ||
* first one. | ||
*/ | ||
export type ParametersExceptFirst<T> = T extends (arg0: any, ...rest: infer U) => any ? U : never; | ||
export {}; | ||
//# sourceMappingURL=types.d.ts.map |
@@ -1,2 +0,2 @@ | ||
export { Combine, EventSchemas, StandardEventSchemaToPayload, StandardEventSchemas, ZodEventSchemas, } from "./components/EventSchemas"; | ||
export { EventSchemas, type Combine, type LiteralZodEventSchema, type StandardEventSchemaToPayload, type StandardEventSchemas, type ZodEventSchemas, } from "./components/EventSchemas"; | ||
export { Inngest } from "./components/Inngest"; | ||
@@ -3,0 +3,0 @@ export type { EventsFromOpts } from "./components/Inngest"; |
{ | ||
"name": "inngest", | ||
"version": "2.4.2-pr-294.6", | ||
"version": "2.4.2-pr-294.7", | ||
"description": "Official SDK for Inngest.com", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -95,6 +95,15 @@ import { z } from "zod"; | ||
/** | ||
* The unhashed step name for this operation. | ||
* The unhashed step name for this operation. This is a legacy field that is | ||
* sometimes used for critical data, like the sleep duration for | ||
* `step.sleep()`. | ||
* | ||
* @deprecated For display name, use `displayName` instead. | ||
*/ | ||
name?: string; | ||
/** | ||
* An optional name for this step that can be used to display in the Inngest | ||
* UI. | ||
*/ | ||
displayName?: string; | ||
/** | ||
* Any additional data required for this operation to send to Inngest. This | ||
@@ -843,5 +852,11 @@ * is not compared when confirming that the operation was completed; use `id` | ||
* The ID to use to memoize the result of this step, ensuring it is run only | ||
* once. | ||
* once. Changing this ID in an existing function will cause the step to be | ||
* run again for in-progress runs; it is recommended to use a stable ID. | ||
*/ | ||
id: string; | ||
/** | ||
* The display name to use for this step in the Inngest UI. This can be | ||
* changed at any time without affecting the step's behaviour. | ||
*/ | ||
name?: string; | ||
} | ||
@@ -848,0 +863,0 @@ export type StepOptionsOrId = StepOptions["id"] | StepOptions; |
@@ -1,2 +0,2 @@ | ||
export declare const version = "2.4.2-pr-294.6"; | ||
export declare const version = "2.4.2-pr-294.7"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -5,3 +5,3 @@ "use strict"; | ||
// Generated by genversion. | ||
exports.version = "2.4.2-pr-294.6"; | ||
exports.version = "2.4.2-pr-294.7"; | ||
//# sourceMappingURL=version.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
515363
7868
370