From 8f5f351a8797763337dbec7e6f971ad52e1923d3 Mon Sep 17 00:00:00 2001 From: Eric Poul <31760529+EricPoul@users.noreply.github.com> Date: Sat, 14 Oct 2023 19:54:25 +0300 Subject: [PATCH] feat(cli): allow build repo class without constructor (#493) --- docs/docs/cli.mdx | 2 +- .../cli/src/builders/active-id.builder.ts | 4 +- .../cli/src/builders/active-ids.builder.ts | 4 +- packages/cli/src/builders/entities.builder.ts | 4 +- packages/cli/src/builders/feature-builder.ts | 2 +- packages/cli/src/builders/repo-builder.ts | 108 ++++++--- .../__snapshots__/repo-builder.spec.ts.snap | 228 +++++++++++++++++- packages/cli/src/specs/repo-builder.spec.ts | 144 ++++++++++- packages/cli/src/types.ts | 2 +- packages/cli/src/utils.ts | 2 +- 10 files changed, 446 insertions(+), 54 deletions(-) diff --git a/docs/docs/cli.mdx b/docs/docs/cli.mdx index 18c23552..90702fc7 100644 --- a/docs/docs/cli.mdx +++ b/docs/docs/cli.mdx @@ -40,7 +40,7 @@ You can set the configuration by providing the `package.json` file: By default, the `repository` file generates exported functions. If you prefer to use a class, for instance, when working with Angular, you can set this option to `class`. ### `inlineStoreInClass` -By default, a store is created outside of the class. If you prefer creating the store inside a class you can set this option to `true`. It might be helpful when you create a `component store` or you want to set the initial value to the store given via Angular DI (Works only with `repoTemplate` set as `class`). +By default, a store is created outside of the class. If you prefer creating the store inside a class you can set this option to `true` or `withoutConstructor`. It might be helpful when you create a `component store` or you want to set the initial value to the store given via Angular DI (Works only with `repoTemplate` set as `class`). ### `idKey` The default `idKey` for the package `@ngneat/elf-entities` is `id`. By setting this option, you can change it globally. diff --git a/packages/cli/src/builders/active-id.builder.ts b/packages/cli/src/builders/active-id.builder.ts index b4cf3bcd..c349d1c3 100644 --- a/packages/cli/src/builders/active-id.builder.ts +++ b/packages/cli/src/builders/active-id.builder.ts @@ -28,13 +28,13 @@ export class ActiveIdBuilder extends FeatureBuilder { kind: StructureKind.Property, }; - if (this.isStoreInlinedInClass) { + if (this.repoConstructor) { this.repo.insertProperty(0, { ...memberData, type: `Observable<${this.storeSingularNames.className} | undefined>`, }); - this.repoConstructor?.addStatements( + this.repoConstructor.addStatements( `this.${memberData.name} = ${initializer};` ); } else { diff --git a/packages/cli/src/builders/active-ids.builder.ts b/packages/cli/src/builders/active-ids.builder.ts index 90ce5790..789c86eb 100644 --- a/packages/cli/src/builders/active-ids.builder.ts +++ b/packages/cli/src/builders/active-ids.builder.ts @@ -28,13 +28,13 @@ export class ActiveIdsBuilder extends FeatureBuilder { kind: StructureKind.Property, }; - if (this.isStoreInlinedInClass) { + if (this.repoConstructor) { this.repo.insertProperty(0, { ...memberData, type: `Observable<${this.storeSingularNames.className}[]>`, }); - this.repoConstructor?.addStatements( + this.repoConstructor.addStatements( `this.${memberData.name} = ${initializer};` ); } else { diff --git a/packages/cli/src/builders/entities.builder.ts b/packages/cli/src/builders/entities.builder.ts index 20c2c370..4d6df2f8 100644 --- a/packages/cli/src/builders/entities.builder.ts +++ b/packages/cli/src/builders/entities.builder.ts @@ -72,7 +72,7 @@ export class EntitiesBuilder extends FeatureBuilder { kind: StructureKind.Property, }; - if (this.isStoreInlinedInClass) { + if (this.repoConstructor) { this.addImport('Observable', 'rxjs'); this.repo.insertProperty(0, { @@ -80,7 +80,7 @@ export class EntitiesBuilder extends FeatureBuilder { type: `Observable<${this.storeSingularNames.className}[]>`, }); - this.repoConstructor?.addStatements( + this.repoConstructor.addStatements( `this.${memberData.name} = ${initializer};` ); } else { diff --git a/packages/cli/src/builders/feature-builder.ts b/packages/cli/src/builders/feature-builder.ts index 71f30782..075c4af4 100644 --- a/packages/cli/src/builders/feature-builder.ts +++ b/packages/cli/src/builders/feature-builder.ts @@ -36,7 +36,7 @@ export abstract class FeatureBuilder { protected repo: ClassDeclaration, protected options: Options ) { - if (this.isStoreInlinedInClass) { + if (this.isStoreInlinedInClass === true) { this.repoConstructor = this.repo.getConstructors()[0]; } } diff --git a/packages/cli/src/builders/repo-builder.ts b/packages/cli/src/builders/repo-builder.ts index b0ccdc06..7e93e7a4 100644 --- a/packages/cli/src/builders/repo-builder.ts +++ b/packages/cli/src/builders/repo-builder.ts @@ -27,6 +27,7 @@ export function createRepo(options: Options) { const storeNames = names(storeName); const isFunctionTpl = !options.template || options.template === 'functions'; const isStoreInlinedInClass = !isFunctionTpl && options.inlineStoreInClass; + const classWithConstructor = isStoreInlinedInClass !== 'withoutConstructor'; const project = new Project({ manipulationSettings: { @@ -46,7 +47,7 @@ export function createRepo(options: Options) { }); let repoClassDecConstructor: ConstructorDeclaration | undefined; - if (isStoreInlinedInClass) { + if (isStoreInlinedInClass && classWithConstructor) { repoClassDec.addConstructor(); repoClassDecConstructor = repoClassDec.getConstructors()[0]; } @@ -91,14 +92,21 @@ export function createRepo(options: Options) { [storeOpts, ...propsFactories] ); - if (isStoreInlinedInClass && repoClassDecConstructor) { - addInlineStoreToRepoClass({ - repoClassDec, - repoClassDecConstructor, - options, - store, - storeNames, - }); + if (isStoreInlinedInClass) { + if (repoClassDecConstructor) { + addInlineStoreToRepoClass({ + repoClassDec, + repoClassDecConstructor, + options, + store, + storeNames, + }); + } else { + addInlineStoreToRepoClassWithoutConstructor({ + repoClassDec, + store, + }); + } } else { addStoreToRepo({ repoClassDec, @@ -170,22 +178,16 @@ function addInlineStoreToRepoClass({ storeNames, true ); - const { propertyIndex, methodIndex } = getPositionsOfInlineStoreDeclarations( - classDec, - constructorDec - ); - - const createStoreMethodName = 'createStore'; + const lastPropertyIndex = classDec + .getLastChildByKind(SyntaxKind.PropertyDeclaration) + ?.getChildIndex(); + const propertyIndex = lastPropertyIndex + ? lastPropertyIndex + 1 + : constructorDec.getChildIndex(); - classDec.insertMethod(methodIndex, { - name: createStoreMethodName, - returnType: `typeof store`, - scope: Scope.Private, - statements: (writer) => { - writer.writeLine(`const store = ${printNode(store)};`); - writer.blankLine(); - writer.writeLine(`return store;`); - }, + const createStoreMethodName = addCreateStoreMethod({ + repoClassDec: classDec, + store, }); constructorDec.insertStatements( @@ -203,6 +205,28 @@ function addInlineStoreToRepoClass({ } } +function addInlineStoreToRepoClassWithoutConstructor({ + repoClassDec: classDec, + store, +}: { + repoClassDec: ClassDeclaration; + store: CallExpression; +}) { + const createStoreMethodName = addCreateStoreMethod({ + repoClassDec: classDec, + store, + }); + + classDec.insertProperty(0, { + name: 'store', + scope: Scope.Private, + isReadonly: true, + initializer: `this.${createStoreMethodName}()`, + }); + + classDec.insertMember(1, '\n'); +} + function toFunctions(sourceFile: SourceFile, classDec: ClassDeclaration) { const exported: string[] = []; @@ -221,21 +245,25 @@ function toFunctions(sourceFile: SourceFile, classDec: ClassDeclaration) { ); } -function getPositionsOfInlineStoreDeclarations( - classDec: ClassDeclaration, - constructorDec: ConstructorDeclaration -) { - const lastPropertyIndex = classDec - .getLastChildByKind(SyntaxKind.PropertyDeclaration) - ?.getChildIndex(); - const lastMethodIndex = classDec - .getLastChildByKind(SyntaxKind.MethodDeclaration) - ?.getChildIndex(); +function addCreateStoreMethod({ + repoClassDec: classDec, + store, +}: { + repoClassDec: ClassDeclaration; + store: CallExpression; +}): string { + const createStoreMethodName = 'createStore'; + + classDec.addMethod({ + name: createStoreMethodName, + returnType: `typeof store`, + scope: Scope.Private, + statements: (writer) => { + writer.writeLine(`const store = ${printNode(store)};`); + writer.blankLine(); + writer.writeLine(`return store;`); + }, + }); - return { - methodIndex: (lastMethodIndex ?? constructorDec.getChildIndex()) + 1, - propertyIndex: lastPropertyIndex - ? lastPropertyIndex + 1 - : constructorDec.getChildIndex(), - }; + return createStoreMethodName; } diff --git a/packages/cli/src/specs/__snapshots__/repo-builder.spec.ts.snap b/packages/cli/src/specs/__snapshots__/repo-builder.spec.ts.snap index dc125db2..714e84cf 100644 --- a/packages/cli/src/specs/__snapshots__/repo-builder.spec.ts.snap +++ b/packages/cli/src/specs/__snapshots__/repo-builder.spec.ts.snap @@ -1,5 +1,58 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Repo Builder all in a class without constructor: all in a class without constructor 1`] = ` +"import { createStore, withProps } from '@ngneat/elf'; +import { withEntities, selectAllEntities, deleteEntities, addEntities, updateEntities, withUIEntities, withActiveId, selectActiveEntity, setActiveId, withActiveIds, selectActiveEntities, toggleActiveIds } from '@ngneat/elf-entities'; +import { withRequestsCache, withRequestsStatus } from '@ngneat/elf-requests'; + +export interface TodoUI { + id: number; +} + +export interface Todo { + id: number; +} + +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface TodosProps { +} + +export class TodosRepository { + private readonly store = this.createStore(); + + activeTodos$ = this.store.pipe(selectActiveEntities()); + activeTodo$ = this.store.pipe(selectActiveEntity()); + todos$ = this.store.pipe(selectAllEntities()); + + deleteTodo(id: Todo['id']) { + this.store.update(deleteEntities(id)); + } + + addTodo(todo: Todo) { + this.store.update(addEntities(todo)); + } + + updateTodo(id: Todo['id'], todo: Partial) { + this.store.update(updateEntities(id, todo)); + } + + setActiveId(id: Todo['id']) { + this.store.update(setActiveId(id)); + } + + toggleActiveIds(ids: Array) { + this.store.update(toggleActiveIds(ids)); + } + + private createStore(): typeof store { + const store = createStore({ name: 'todos' }, withProps({}), withEntities(), withUIEntities(), withActiveId(), withActiveIds(), withRequestsCache<'todos'>(), withRequestsStatus<'todos'>()); + + return store; + } +} +" +`; + exports[`Repo Builder all in a class: all in a class 1`] = ` "import { createStore, withProps } from '@ngneat/elf'; import { withEntities, selectAllEntities, deleteEntities, addEntities, updateEntities, withUIEntities, withActiveId, selectActiveEntity, setActiveId, withActiveIds, selectActiveEntities, toggleActiveIds } from '@ngneat/elf-entities'; @@ -155,6 +208,28 @@ export function toggleActiveTodosIds(ids: Array) { " `; +exports[`Repo Builder withActiveId in a class without constructor: withActiveId in a class without constructor 1`] = ` +"import { createStore } from '@ngneat/elf'; +import { withActiveId, selectActiveEntity, setActiveId } from '@ngneat/elf-entities'; + +export class TodosRepository { + private readonly store = this.createStore(); + + activeTodo$ = this.store.pipe(selectActiveEntity()); + + setActiveId(id: Todo['id']) { + this.store.update(setActiveId(id)); + } + + private createStore(): typeof store { + const store = createStore({ name: 'todos' }, withActiveId()); + + return store; + } +} +" +`; + exports[`Repo Builder withActiveId in a class: withActiveId in a class 1`] = ` "import { createStore } from '@ngneat/elf'; import { withActiveId, selectActiveEntity, setActiveId } from '@ngneat/elf-entities'; @@ -198,6 +273,28 @@ export class TodosRepository { " `; +exports[`Repo Builder withActiveIds in a class without constructor: withActiveIds in a class without constructor 1`] = ` +"import { createStore } from '@ngneat/elf'; +import { withActiveIds, selectActiveEntities, toggleActiveIds } from '@ngneat/elf-entities'; + +export class TodosRepository { + private readonly store = this.createStore(); + + activeTodos$ = this.store.pipe(selectActiveEntities()); + + toggleActiveIds(ids: Array) { + this.store.update(toggleActiveIds(ids)); + } + + private createStore(): typeof store { + const store = createStore({ name: 'todos' }, withActiveIds()); + + return store; + } +} +" +`; + exports[`Repo Builder withActiveIds in a class: withActiveIds in a class 1`] = ` "import { createStore } from '@ngneat/elf'; import { withActiveIds, selectActiveEntities, toggleActiveIds } from '@ngneat/elf-entities'; @@ -241,7 +338,41 @@ export class TodosRepository { " `; -exports[`Repo Builder withEntities idKey in a class: withEntities in a class 1`] = ` +exports[`Repo Builder withEntities idKey in a class without constructor: withEntities idKey in a class without constructor 1`] = ` +"import { createStore } from '@ngneat/elf'; +import { withEntities, selectAllEntities, addEntities, updateEntities, deleteEntities } from '@ngneat/elf-entities'; + +export interface Todo { + _id: number; +} + +export class TodosRepository { + private readonly store = this.createStore(); + + todos$ = this.store.pipe(selectAllEntities()); + + addTodo(todo: Todo) { + this.store.update(addEntities(todo)); + } + + updateTodo(id: Todo['_id'], todo: Partial) { + this.store.update(updateEntities(id, todo)); + } + + deleteTodo(id: Todo['_id']) { + this.store.update(deleteEntities(id)); + } + + private createStore(): typeof store { + const store = createStore({ name: 'todos' }, withEntities({ idKey: '_id' })); + + return store; + } +} +" +`; + +exports[`Repo Builder withEntities idKey in a class: withEntities idKey in a class 1`] = ` "import { createStore } from '@ngneat/elf'; import { withEntities, selectAllEntities, addEntities, updateEntities, deleteEntities } from '@ngneat/elf-entities'; import { Observable } from 'rxjs'; @@ -281,7 +412,7 @@ export class TodosRepository { " `; -exports[`Repo Builder withEntities idKey: withEntities 1`] = ` +exports[`Repo Builder withEntities idKey: withEntities idKey 1`] = ` "import { createStore } from '@ngneat/elf'; import { withEntities, selectAllEntities, addEntities, updateEntities, deleteEntities } from '@ngneat/elf-entities'; @@ -309,6 +440,28 @@ export class TodosRepository { " `; +exports[`Repo Builder withEntities in a class without constructor: withEntities in a class without constructor 1`] = ` +"import { createStore } from '@ngneat/elf'; +import { withEntities, selectAllEntities } from '@ngneat/elf-entities'; + +export interface Todo { + id: number; +} + +export class TodosRepository { + private readonly store = this.createStore(); + + todos$ = this.store.pipe(selectAllEntities()); + + private createStore(): typeof store { + const store = createStore({ name: 'todos' }, withEntities()); + + return store; + } +} +" +`; + exports[`Repo Builder withEntities in a class: withEntities in a class 1`] = ` "import { createStore } from '@ngneat/elf'; import { withEntities, selectAllEntities } from '@ngneat/elf-entities'; @@ -365,6 +518,25 @@ export class TodosRepository { " `; +exports[`Repo Builder withProps in a class without constructor: withProps in a class without constructor 1`] = ` +"import { createStore, withProps } from '@ngneat/elf'; + +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface TodosProps { +} + +export class TodosRepository { + private readonly store = this.createStore(); + + private createStore(): typeof store { + const store = createStore({ name: 'todos' }, withProps({})); + + return store; + } +} +" +`; + exports[`Repo Builder withProps in a class: withProps in a class 1`] = ` "import { createStore, withProps } from '@ngneat/elf'; @@ -402,6 +574,22 @@ export class TodosRepository { " `; +exports[`Repo Builder withRequestsCache in a class without constructor: withRequestsCache in a class without constructor 1`] = ` +"import { createStore } from '@ngneat/elf'; +import { withRequestsCache } from '@ngneat/elf-requests'; + +export class TodosRepository { + private readonly store = this.createStore(); + + private createStore(): typeof store { + const store = createStore({ name: 'todos' }, withRequestsCache<'todos'>()); + + return store; + } +} +" +`; + exports[`Repo Builder withRequestsCache in a class: withRequestsCache in a class 1`] = ` "import { createStore } from '@ngneat/elf'; import { withRequestsCache } from '@ngneat/elf-requests'; @@ -433,6 +621,22 @@ export class TodosRepository { " `; +exports[`Repo Builder withRequestsStatus in a class without constructor: withRequestsStatus in a class without constructor 1`] = ` +"import { createStore } from '@ngneat/elf'; +import { withRequestsStatus } from '@ngneat/elf-requests'; + +export class TodosRepository { + private readonly store = this.createStore(); + + private createStore(): typeof store { + const store = createStore({ name: 'todos' }, withRequestsStatus<'todos'>()); + + return store; + } +} +" +`; + exports[`Repo Builder withRequestsStatus in a class: withRequestsStatus in a class 1`] = ` "import { createStore } from '@ngneat/elf'; import { withRequestsStatus } from '@ngneat/elf-requests'; @@ -464,6 +668,26 @@ export class TodosRepository { " `; +exports[`Repo Builder withUIEntities in a class without constructor: withUIEntities in a class without constructor 1`] = ` +"import { createStore } from '@ngneat/elf'; +import { withUIEntities } from '@ngneat/elf-entities'; + +export interface TodoUI { + id: number; +} + +export class TodosRepository { + private readonly store = this.createStore(); + + private createStore(): typeof store { + const store = createStore({ name: 'todos' }, withUIEntities()); + + return store; + } +} +" +`; + exports[`Repo Builder withUIEntities in a class: withUIEntities in a class 1`] = ` "import { createStore } from '@ngneat/elf'; import { withUIEntities } from '@ngneat/elf-entities'; diff --git a/packages/cli/src/specs/repo-builder.spec.ts b/packages/cli/src/specs/repo-builder.spec.ts index f7c74f73..acbca2f3 100644 --- a/packages/cli/src/specs/repo-builder.spec.ts +++ b/packages/cli/src/specs/repo-builder.spec.ts @@ -29,6 +29,20 @@ describe('Repo Builder', () => { expect(output).toMatchSnapshot('withProps in a class'); }); + it('withProps in a class without constructor', () => { + const output = createRepo({ + idKey: 'id', + features: ['withProps'], + crud: [], + template: 'class', + inlineStoreInClass: 'withoutConstructor', + storeName: 'todos', + path: '', + }); + + expect(output).toMatchSnapshot('withProps in a class without constructor'); + }); + it('withRequestsCache', () => { const output = createRepo({ idKey: 'id', @@ -56,6 +70,22 @@ describe('Repo Builder', () => { expect(output).toMatchSnapshot('withRequestsCache in a class'); }); + it('withRequestsCache in a class without constructor', () => { + const output = createRepo({ + idKey: 'id', + features: ['withRequestsCache'], + crud: [], + template: 'class', + inlineStoreInClass: 'withoutConstructor', + storeName: 'todos', + path: '', + }); + + expect(output).toMatchSnapshot( + 'withRequestsCache in a class without constructor' + ); + }); + it('withRequestsStatus', () => { const output = createRepo({ idKey: 'id', @@ -83,6 +113,22 @@ describe('Repo Builder', () => { expect(output).toMatchSnapshot('withRequestsStatus in a class'); }); + it('withRequestsStatus in a class without constructor', () => { + const output = createRepo({ + idKey: 'id', + features: ['withRequestsStatus'], + crud: [], + template: 'class', + inlineStoreInClass: 'withoutConstructor', + storeName: 'todos', + path: '', + }); + + expect(output).toMatchSnapshot( + 'withRequestsStatus in a class without constructor' + ); + }); + it('withActiveId', () => { const output = createRepo({ idKey: 'id', @@ -110,6 +156,22 @@ describe('Repo Builder', () => { expect(output).toMatchSnapshot('withActiveId in a class'); }); + it('withActiveId in a class without constructor', () => { + const output = createRepo({ + idKey: 'id', + features: ['withActiveId'], + crud: [], + template: 'class', + inlineStoreInClass: 'withoutConstructor', + storeName: 'todos', + path: '', + }); + + expect(output).toMatchSnapshot( + 'withActiveId in a class without constructor' + ); + }); + it('withActiveIds', () => { const output = createRepo({ idKey: 'id', @@ -137,6 +199,22 @@ describe('Repo Builder', () => { expect(output).toMatchSnapshot('withActiveIds in a class'); }); + it('withActiveIds in a class without constructor', () => { + const output = createRepo({ + idKey: 'id', + features: ['withActiveIds'], + crud: [], + template: 'class', + inlineStoreInClass: 'withoutConstructor', + storeName: 'todos', + path: '', + }); + + expect(output).toMatchSnapshot( + 'withActiveIds in a class without constructor' + ); + }); + it('withEntities', () => { const output = createRepo({ idKey: 'id', @@ -164,6 +242,22 @@ describe('Repo Builder', () => { expect(output).toMatchSnapshot('withEntities in a class'); }); + it('withEntities in a class without constructor', () => { + const output = createRepo({ + idKey: 'id', + features: ['withEntities'], + crud: [], + template: 'class', + inlineStoreInClass: 'withoutConstructor', + storeName: 'todos', + path: '', + }); + + expect(output).toMatchSnapshot( + 'withEntities in a class without constructor' + ); + }); + it('withEntities idKey', () => { const output = createRepo({ idKey: '_id', @@ -174,7 +268,7 @@ describe('Repo Builder', () => { template: 'class', }); - expect(output).toMatchSnapshot('withEntities'); + expect(output).toMatchSnapshot('withEntities idKey'); }); it('withEntities idKey in a class', () => { @@ -188,7 +282,23 @@ describe('Repo Builder', () => { path: '', }); - expect(output).toMatchSnapshot('withEntities in a class'); + expect(output).toMatchSnapshot('withEntities idKey in a class'); + }); + + it('withEntities idKey in a class without constructor', () => { + const output = createRepo({ + idKey: '_id', + features: ['withEntities'], + crud: ['addEntities', 'updateEntities', 'deleteEntities'], + template: 'class', + inlineStoreInClass: 'withoutConstructor', + storeName: 'todos', + path: '', + }); + + expect(output).toMatchSnapshot( + 'withEntities idKey in a class without constructor' + ); }); it('withUIEntities', () => { @@ -218,6 +328,22 @@ describe('Repo Builder', () => { expect(output).toMatchSnapshot('withUIEntities in a class'); }); + it('withUIEntities in a class without constructor', () => { + const output = createRepo({ + idKey: 'id', + features: ['withUIEntities'], + crud: [], + template: 'class', + inlineStoreInClass: 'withoutConstructor', + storeName: 'todos', + path: '', + }); + + expect(output).toMatchSnapshot( + 'withUIEntities in a class without constructor' + ); + }); + it('all', () => { const output = createRepo({ idKey: 'id', @@ -245,6 +371,20 @@ describe('Repo Builder', () => { expect(output).toMatchSnapshot('all in a class'); }); + it('all in a class without constructor', () => { + const output = createRepo({ + idKey: 'id', + features: baseFeatures.map(({ value }) => value), + crud: ['deleteEntities', 'addEntities', 'updateEntities'], + template: 'class', + inlineStoreInClass: 'withoutConstructor', + storeName: 'todos', + path: '', + }); + + expect(output).toMatchSnapshot('all in a class without constructor'); + }); + it('should support function template', () => { const output = createRepo({ idKey: 'id', diff --git a/packages/cli/src/types.ts b/packages/cli/src/types.ts index 02408c08..b1a3b741 100644 --- a/packages/cli/src/types.ts +++ b/packages/cli/src/types.ts @@ -9,7 +9,7 @@ export interface Options { path: string; idKey: string; template?: 'class' | 'functions'; - inlineStoreInClass?: boolean; + inlineStoreInClass?: boolean | 'withoutConstructor'; hooks?: Array; } diff --git a/packages/cli/src/utils.ts b/packages/cli/src/utils.ts index 5182856d..36082380 100644 --- a/packages/cli/src/utils.ts +++ b/packages/cli/src/utils.ts @@ -11,7 +11,7 @@ export function coerceArray(value: T[] | T): T[] { export function resolveStoreVariableName( template: Options['template'], { propertyName }: ReturnType, - inlineStoreInClass: boolean = false + inlineStoreInClass: Options['inlineStoreInClass'] = false ) { return template === 'functions' ? `${propertyName}Store`