Releases: JorgenVatle/feathers-factory
Release list
feathers-factory@5.1.0-beta.6
Patch Changes
- 02ef02e: Use overrides provided to Factory create() method for narrowing return type of underlying service.
feathers-factory@5.1.0-beta.5
Patch Changes
- 56777a3: Fix issue where extending an existing Factory instance would only include the provided overrides in the resulting template
feathers-factory@5.1.0-beta.4
feathers-factory@5.1.0-beta.3
Patch Changes
-
f015dea: Add missing exports for ExtendSchema and ResolveField helper types.
- Implemented type narrowing for overrides provided to FactoryTemplate's
resolve()method. Fixes issues where
optional types remain optional even when the provided overrides invalidate that type.
- Implemented type narrowing for overrides provided to FactoryTemplate's
feathers-factory@5.1.0-beta.2
Minor Changes
-
43c30d2: Add extendable
_create()method to Factory class to allow for custom error handling.- Make
paramsoptional inFactory.extend()method to match the Factory constructor signature. - Fix type issue where
Factory.unsafeExtend()output types would be partially resolved. Yielding methods and functions when callingcreate() - Added
ExtendSchemahelper type for appending new fields/types on an existing template schema.
- Make
feathers-factory@5.1.0-beta.1
Minor Changes
-
1dd3b37: Add
extendandunsafeExtendmethods to Factories, and improved TSDocs.- Added
Factory.extend()- creates a new factory class with the same expected input and output types from the underlying service. - Added
Factory.unsafeExtend()- creates a new factory class where the input/output types of the service can be overriden to provide values not otherwise allowed by the service's create() method. - Added and expanded TSDocs for
Factory,FactoryTemplateandTemplateContextmethods. - Renamed
Factory.get()toFactory.resolve()to be more in line with the signatures used in the rest of the library. - Renamed
TemplateSchemaOverridestype helper toSchemaOverridesto avoid unnecessary verboseness. - Renamed
ResolveSchemaOutputandSchemaFieldValuetype helpers to simplyResolveSchemaandResolveFieldrespectively. These helpers are primarily internal, though are exported as they may be useful in some use cases. - Changed
InferOutputtype helper to work with any input type so it is less finicky to use. - Simplified type hints for
FactoryTemplate.resolve()andFactoryTemplate.extend()method parameters and resulting output. - Improved readability of resulting type hints originating from the
InferOutputtype helper. - Included internal FeathersFactoryError classes in package exports.
- Added
v5.1.0-beta.0
Minor Changes
-
63dcd30: Omit confusing internal type for unwrapping FactoryTemplate schemas as it would un-intuitively not work with
FactoryTemplateclass instance types. A new type that will work with both has been added in its place.Fixed issue where the resolved type of
this.get()would equate to unknown when referencing other dynamic methods.
v5.0.1
v5.0.0
Major Changes
-
152e834: Improved compatability and type inference with non-standard-feathers services.
- Factories are no longer tied to just Feathers services. Just supply an object with a
create()method in place
of the service.
import Factory from "./Factory"; const customFactory = new Factory({ /** * Types will be inferred from this data argument. */ create(data: { _id: string; username: string }) { // ... }, });
Breaking changes
The runtime behavior is not much different from prior versions. However the
thistype for factories has been revamped
to expose contextual properties using athis.get(propName)signature instead.Feathers Factory v4
new Factory(UserService, { firstName: faker.person.firstName, lastName: faker.person.lastName, fullName() { return `${this.firstName} ${this.lastName}`; }, });
Feathers Factory v5
You can still access properties using
this.firstName- though they are omitted from yourthistype to encourage
the use of the helper method instead.This change should make it more clear which properties depend on each other and whether they're available
only asynchronously.new Factory(UserService, { firstName: faker.person.firstName, lastName: faker.person.lastName, fullName() { return `${this.get("firstName")} ${this.get("lastName")}`; }, });
- Factories are no longer tied to just Feathers services. Just supply an object with a
Minor Changes
-
2033f26: Infer service Params type from service type definition instead of relying on external Feathers Params type.
-
285e8f0: Add exports for internal schema and template merging utilities
-
7aa9357: Refactor internal data generator to be less complex and open up for usage outside a factory context.
- Replaced
DataGeneratortype with more extensibleFactoryTemplateclass. - Added option to access the current resolver context through arrow functions.
- Added option to
call()peer properties. This will bypass the current
context's cached result for a given property. Essentially re-running a function
to create more than one output for a given field.
Factory Template
They work just like factories. Just that they are not tied to any underlying
service schema and will only mock out structured data consistent within its
own context.import { FactoryTemplate } from "feathers-factory"; const shopTemplate = new FactoryTemplate({ products: () => [productTemplate.resolve()], createdAt: () => new Date(), }); const productTemplate = new FactoryTemplate({ _id: () => faker.random.uuid(), shop: () => shopTemplate.resolve(), }); const orderTemplate = new FactoryTemplate({ shop: () => shopTemplate.resolve(), // These will only resolve once to the result of the above shop property createdAt: (ctx) => faker.date.dateAfter(ctx.get("shop.createdAt")), products: (ctx) => [ctx.get("shop.products.0")], relatedOffers: (ctx) => [ ctx.call("shop"), // Creates a new shop and products ctx.call("shop"), // And yet another shop ], });
Use with factories
Factory templates can optionally be passed directly to the factories you define.
// import orderTemplate from 'example above ⇡' import { Factory } from "feathers-factory"; const orderFactory = new Factory(app.service("/orders"), orderTemplate);
Optional typings for GlobalFactories
You can now optionally add strict factory types for globally defined factories.
// import orderFactory from 'example above ⇡' import { GlobalFactories } from "feathers-factory"; GlobalFactories.define("order", orderFactory); declare module "feathers-factory" { interface GlobalFactories { orders: typeof orderFactory; } } GlobalFactories.create("order"); // -> { shop: {...}, createdAt: Date, .... }
- Replaced
-
c2ef1e9: Add types for accessing deeply nested template properties using object dot notation
Patch Changes
v5.0.0-beta.5
Minor Changes
- 2033f26: Infer service Params type from service type definition instead of relying on external Feathers Params type.