Skip to content

Releases: JorgenVatle/feathers-factory

feathers-factory@5.1.0-beta.6

Pre-release

Choose a tag to compare

@github-actions github-actions released this 28 May 12:24
613d81d

Patch Changes

  • 02ef02e: Use overrides provided to Factory create() method for narrowing return type of underlying service.

feathers-factory@5.1.0-beta.5

Pre-release

Choose a tag to compare

@github-actions github-actions released this 28 May 08:29
6a98956

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

Pre-release

Choose a tag to compare

@github-actions github-actions released this 28 May 08:17
ed33cdf

Patch Changes

  • ca75259: Fix issue where optional properties ({ optional?: true }) in SchemaOverrides would not be narrowed correctly.
  • 4e8403b: Fix issue where exceptions during schema context resolve loses stack trackes.

feathers-factory@5.1.0-beta.3

Pre-release

Choose a tag to compare

@github-actions github-actions released this 28 May 05:24
a096043

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.

feathers-factory@5.1.0-beta.2

Pre-release

Choose a tag to compare

@github-actions github-actions released this 28 May 03:41
6c96f10

Minor Changes

  • 43c30d2: Add extendable _create() method to Factory class to allow for custom error handling.

    • Make params optional in Factory.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 calling create()
    • Added ExtendSchema helper type for appending new fields/types on an existing template schema.

feathers-factory@5.1.0-beta.1

Pre-release

Choose a tag to compare

Minor Changes

  • 1dd3b37: Add extend and unsafeExtend methods 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, FactoryTemplate and TemplateContext methods.
    • Renamed Factory.get() to Factory.resolve() to be more in line with the signatures used in the rest of the library.
    • Renamed TemplateSchemaOverrides type helper to SchemaOverrides to avoid unnecessary verboseness.
    • Renamed ResolveSchemaOutput and SchemaFieldValue type helpers to simply ResolveSchema and ResolveField respectively. These helpers are primarily internal, though are exported as they may be useful in some use cases.
    • Changed InferOutput type helper to work with any input type so it is less finicky to use.
    • Simplified type hints for FactoryTemplate.resolve() and FactoryTemplate.extend() method parameters and resulting output.
    • Improved readability of resulting type hints originating from the InferOutput type helper.
    • Included internal FeathersFactoryError classes in package exports.

v5.1.0-beta.0

v5.1.0-beta.0 Pre-release
Pre-release

Choose a tag to compare

@github-actions github-actions released this 26 May 20:26
da7b35b

Minor Changes

  • 63dcd30: Omit confusing internal type for unwrapping FactoryTemplate schemas as it would un-intuitively not work with
    FactoryTemplate class 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

Choose a tag to compare

@github-actions github-actions released this 16 May 13:36
bb084b7

Patch Changes

  • 7b70337: Fix type inference edge-cases with FactoryTemplate output and 'this' context with some async contexts.

v5.0.0

Choose a tag to compare

@github-actions github-actions released this 16 May 05:08
194a30f

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 this type for factories has been revamped
    to expose contextual properties using a this.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 your this type 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")}`;
      },
    });

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 DataGenerator type with more extensible FactoryTemplate class.
    • 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, .... }
  • c2ef1e9: Add types for accessing deeply nested template properties using object dot notation

Patch Changes

  • 5bc6553: Add missing implementation for TemplateContext call() method
  • cc64e9d: Move type-fest from devDependencies into dependencies to avoid missing types in peer projects.

v5.0.0-beta.5

v5.0.0-beta.5 Pre-release
Pre-release

Choose a tag to compare

@github-actions github-actions released this 16 May 03:56
10433f4

Minor Changes

  • 2033f26: Infer service Params type from service type definition instead of relying on external Feathers Params type.