From fdafe58fd50f0afb0949f81ecf3d8530a33f4d2a Mon Sep 17 00:00:00 2001 From: Gregor Becker Date: Fri, 8 Sep 2023 15:37:09 +0200 Subject: [PATCH 01/10] feat(pinia-orm-1437): Add namespace option for the store --- .../2.api/2.model/1.options/3.namespace.md | 30 ++++++++ docs/content/2.api/5.configuration.md | 12 ++-- packages/pinia-orm/src/model/Model.ts | 20 ++++++ packages/pinia-orm/src/query/Query.ts | 2 +- .../pinia-orm/src/repository/Repository.ts | 2 +- packages/pinia-orm/src/store/Config.ts | 1 + packages/pinia-orm/src/store/Store.ts | 1 + .../feature/repository/retrieves_has.spec.ts | 6 ++ .../repository/retrieves_has_or.spec.ts | 14 ++++ .../pinia-orm/tests/unit/PiniaORM.spec.ts | 71 +++++++++---------- .../tests/unit/model/Model_STI.spec.ts | 2 +- 11 files changed, 117 insertions(+), 44 deletions(-) create mode 100644 docs/content/2.api/2.model/1.options/3.namespace.md diff --git a/docs/content/2.api/2.model/1.options/3.namespace.md b/docs/content/2.api/2.model/1.options/3.namespace.md new file mode 100644 index 000000000..ca2efffa0 --- /dev/null +++ b/docs/content/2.api/2.model/1.options/3.namespace.md @@ -0,0 +1,30 @@ +--- +title: 'entity' +description: 'Defines the entity name in the store' +--- + +# `namespace` + +Define a namespace if you have multiple equal entity names. +Resulting in "{namespace}/{entity}" + +## Usage + +````js +class User extends Model { + static entity = 'users' + + static namespace = 'orm' + + static fields () { + return { + userId: this.attr(null) + } + } +} +```` + +## Typescript Declarations +````ts +const namespace: string = '' +```` diff --git a/docs/content/2.api/5.configuration.md b/docs/content/2.api/5.configuration.md index 60a1dd879..86bd1fef1 100644 --- a/docs/content/2.api/5.configuration.md +++ b/docs/content/2.api/5.configuration.md @@ -8,11 +8,12 @@ icon: heroicons-outline:adjustments ## `model` -| Option | Default | Description | -|------------|:-------:|:--------------------------------------------------------| -| `withMeta` | `false` | Activates the `_meta` field to be saved for every model | -| `visible` | `[*]` | Sets default visible fields for every model | -| `hidden` | `[]` | Sets default hidden fields for every model | +| Option | Default | Description | +|-------------|:-------:|:--------------------------------------------------------| +| `withMeta` | `false` | Activates the `_meta` field to be saved for every model | +| `visible` | `[*]` | Sets default visible fields for every model | +| `hidden` | `[]` | Sets default hidden fields for every model | +| `namespace` | `''` | Define a namespace for the store as prefix | ## `cache` @@ -27,6 +28,7 @@ icon: heroicons-outline:adjustments export interface ModelConfigOptions { withMeta?: boolean hidden?: string[] + namespace?: string visible?: string[] } diff --git a/packages/pinia-orm/src/model/Model.ts b/packages/pinia-orm/src/model/Model.ts index 8caf9d022..36389a2a9 100644 --- a/packages/pinia-orm/src/model/Model.ts +++ b/packages/pinia-orm/src/model/Model.ts @@ -72,6 +72,12 @@ export class Model { */ static baseEntity: string + /** + * Define a namespace if you have multiple equal entity names. + * Resulting in "{namespace}/{entity}" + */ + static namespace: string + /** * The primary key for the model. */ @@ -601,6 +607,20 @@ export class Model { return this.$self().config } + /** + * Get the namespace. + */ + $namespace (): String { + return this.$self().namespace ?? config.model.namespace + } + + /** + * Get the store name. + */ + $storeName (): String { + return (this.$namespace() ? this.$namespace() + '/' : '') + this.$baseEntity() + } + /** * Get the base entity for this model. */ diff --git a/packages/pinia-orm/src/query/Query.ts b/packages/pinia-orm/src/query/Query.ts index 9f5349a17..6ce793fa4 100644 --- a/packages/pinia-orm/src/query/Query.ts +++ b/packages/pinia-orm/src/query/Query.ts @@ -161,7 +161,7 @@ export class Query { * Commit a store action and get the data */ protected commit (name: string, payload?: any) { - const store = useDataStore(this.model.$baseEntity(), this.model.$piniaOptions(), this)(this.pinia) + const store = useDataStore(this.model.$storeName(), this.model.$piniaOptions(), this)(this.pinia) if (name && typeof store[name] === 'function') { store[name](payload, false) } if (this.cache && ['get', 'all', 'insert', 'flush', 'delete', 'update', 'destroy'].includes(name)) { this.cache.clear() } diff --git a/packages/pinia-orm/src/repository/Repository.ts b/packages/pinia-orm/src/repository/Repository.ts index e44a031d8..3a44fe72a 100644 --- a/packages/pinia-orm/src/repository/Repository.ts +++ b/packages/pinia-orm/src/repository/Repository.ts @@ -116,7 +116,7 @@ export class Repository { * Returns the pinia store used with this model */ piniaStore () { - return useDataStore(this.model.$entity(), this.model.$piniaOptions(), this.query())(this.pinia) + return useDataStore(this.model.$storeName(), this.model.$piniaOptions(), this.query())(this.pinia) } /** diff --git a/packages/pinia-orm/src/store/Config.ts b/packages/pinia-orm/src/store/Config.ts index 3a6591a57..6ae236215 100644 --- a/packages/pinia-orm/src/store/Config.ts +++ b/packages/pinia-orm/src/store/Config.ts @@ -3,6 +3,7 @@ import type { FilledInstallOptions } from './Store' export const CONFIG_DEFAULTS = { model: { + namespace: '', withMeta: false, hidden: ['_meta'], visible: ['*'], diff --git a/packages/pinia-orm/src/store/Store.ts b/packages/pinia-orm/src/store/Store.ts index c6fa91bbf..4d9b8819c 100644 --- a/packages/pinia-orm/src/store/Store.ts +++ b/packages/pinia-orm/src/store/Store.ts @@ -6,6 +6,7 @@ import { CONFIG_DEFAULTS, config } from './Config' export interface ModelConfigOptions { withMeta?: boolean hidden?: string[] + namespace?: string visible?: string[] } diff --git a/packages/pinia-orm/tests/feature/repository/retrieves_has.spec.ts b/packages/pinia-orm/tests/feature/repository/retrieves_has.spec.ts index 8ed4ced40..be82644db 100644 --- a/packages/pinia-orm/tests/feature/repository/retrieves_has.spec.ts +++ b/packages/pinia-orm/tests/feature/repository/retrieves_has.spec.ts @@ -172,11 +172,14 @@ describe('feature/repository/retrieves_has', () => { query.where('title', 'Title 03') }).get() + const users3 = userRepo.whereHas('post').get() + const expected = [ { id: 2, name: 'Jane Doe' } ] expect(users).toHaveLength(1) + expect(users3).toHaveLength(2) assertInstanceOf(users, User) assertModels(users, expected) assertModels(users2, [{ id: 1, name: 'John Doe' }, { id: 2, name: 'Jane Doe' }]) @@ -202,12 +205,15 @@ describe('feature/repository/retrieves_has', () => { query.where('title', 'Title 03') }).get() + const users2 = userRepo.whereDoesntHave('posts').get() + const expected = [ { id: 2, name: 'Jane Doe' }, { id: 3, name: 'Johnny Doe' } ] expect(users).toHaveLength(2) + expect(users2).toHaveLength(1) assertInstanceOf(users, User) assertModels(users, expected) }) diff --git a/packages/pinia-orm/tests/feature/repository/retrieves_has_or.spec.ts b/packages/pinia-orm/tests/feature/repository/retrieves_has_or.spec.ts index 5a6bdbf7b..f00754fc8 100644 --- a/packages/pinia-orm/tests/feature/repository/retrieves_has_or.spec.ts +++ b/packages/pinia-orm/tests/feature/repository/retrieves_has_or.spec.ts @@ -102,12 +102,20 @@ describe('feature/repository/retrieves_has_or', () => { .where('name', 'Johnny Doe') .get() + const users2 = userRepo + .orWhereHas('posts') + .where('name', 'Johnny Doe') + .get() + const expected = [ { id: 2, name: 'Jane Doe' }, { id: 3, name: 'Johnny Doe' } ] + + expect(users).toHaveLength(2) + expect(users2).toHaveLength(3) assertInstanceOf(users, User) assertModels(users, expected) }) @@ -135,12 +143,18 @@ describe('feature/repository/retrieves_has_or', () => { .where('name', 'Johnny Doe') .get() + const users2 = userRepo + .orWhereDoesntHave('posts') + .where('name', 'Johnny Doe') + .get() + const expected = [ { id: 2, name: 'Jane Doe' }, { id: 3, name: 'Johnny Doe' } ] expect(users).toHaveLength(2) + expect(users2).toHaveLength(1) assertInstanceOf(users, User) assertModels(users, expected) }) diff --git a/packages/pinia-orm/tests/unit/PiniaORM.spec.ts b/packages/pinia-orm/tests/unit/PiniaORM.spec.ts index b66efc34a..ffee3bce4 100644 --- a/packages/pinia-orm/tests/unit/PiniaORM.spec.ts +++ b/packages/pinia-orm/tests/unit/PiniaORM.spec.ts @@ -45,15 +45,6 @@ describe('unit/PiniaORM', () => { }) it('pass config "model.visible"', () => { - Model.clearRegistries() - class User extends Model { - static entity = 'users' - - @Attr(0) declare id: number - @Str('') declare name: string - @Str('') declare username: string - } - createPiniaORM({ model: { visible: ['name'] } }) const userRepo = useRepo(User) @@ -68,15 +59,6 @@ describe('unit/PiniaORM', () => { }) it('pass config "cache false"', () => { - Model.clearRegistries() - class User extends Model { - static entity = 'users' - - @Attr(0) declare id: number - @Str('') declare name: string - @Str('') declare username: string - } - createPiniaORM({ cache: false }) const userRepo = useRepo(User) @@ -90,15 +72,6 @@ describe('unit/PiniaORM', () => { }) it('pass config "cache true"', () => { - Model.clearRegistries() - class User extends Model { - static entity = 'users' - - @Attr(0) declare id: number - @Str('') declare name: string - @Str('') declare username: string - } - createPiniaORM({ cache: true }) const userRepo = useRepo(User) @@ -112,15 +85,6 @@ describe('unit/PiniaORM', () => { }) it('pass config "cache.shared false"', () => { - Model.clearRegistries() - class User extends Model { - static entity = 'users' - - @Attr(0) declare id: number - @Str('') declare name: string - @Str('') declare username: string - } - createPiniaORM({ cache: { shared: false @@ -136,4 +100,39 @@ describe('unit/PiniaORM', () => { expect(userRepo.cache()).toBeInstanceOf(WeakCache) }) + + it('can a pass a namespace for each model', () => { + createPiniaORM({ model: { namespace: 'orm' } }) + + const userRepo = useRepo(User) + const user = userRepo.save({ + id: 1, + name: 'John', + username: 'JD' + }) + + expect(user.$storeName()).toBe('orm/users') + }) + + it('can overwrite namespace for a model', () => { + class User extends Model { + static entity = 'users' + + static namespace = 'otherOrm' + + @Attr(0) declare id: number + @Str('') declare name: string + @Str('') declare username: string + } + createPiniaORM({ model: { nameSpace: 'orm' } }) + + const userRepo = useRepo(User) + const user = userRepo.save({ + id: 1, + name: 'John', + username: 'JD' + }) + + expect(user.$storeName()).toBe('otherOrm/users') + }) }) diff --git a/packages/pinia-orm/tests/unit/model/Model_STI.spec.ts b/packages/pinia-orm/tests/unit/model/Model_STI.spec.ts index c81f4d107..533744258 100644 --- a/packages/pinia-orm/tests/unit/model/Model_STI.spec.ts +++ b/packages/pinia-orm/tests/unit/model/Model_STI.spec.ts @@ -305,7 +305,7 @@ describe('unit/model/Model_STI', () => { 2: { id: 2, type: 'ADULT', name: 'Jane Doe', job: 'Software Engineer' } } }) - const persons = useRepo(Person).all() + const persons = useRepo(Person).query().all() expect(persons[0]).toBeInstanceOf(Person) expect(persons[0]).not.toHaveProperty('type') expect(persons[1]).toBeInstanceOf(Adult) From e1d55cb83398f73f0b704792217a2ef0bec8d2d8 Mon Sep 17 00:00:00 2001 From: Gregor Becker Date: Fri, 8 Sep 2023 15:45:21 +0200 Subject: [PATCH 02/10] refactor(pinia-orm): change build command & fix small typo --- package.json | 2 +- packages/pinia-orm/src/model/Model.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1777a2e24..d2d60264b 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "release": "node scripts/release.mjs", "size": "lerna run size --scope pinia-orm", - "build": "lerna run build --ignore @pina-orm/playground-*", + "build": "pnpm --filter './packages/**' build", "sponsor": "sponsorkit", "build:ci": "lerna run build --ignore @pina-orm/playground-* --ignore @pinia-orm/nuxt", "build:pinia-orm": "lerna run build --scope pinia-orm", diff --git a/packages/pinia-orm/src/model/Model.ts b/packages/pinia-orm/src/model/Model.ts index 36389a2a9..71c284305 100644 --- a/packages/pinia-orm/src/model/Model.ts +++ b/packages/pinia-orm/src/model/Model.ts @@ -617,7 +617,7 @@ export class Model { /** * Get the store name. */ - $storeName (): String { + $storeName (): string { return (this.$namespace() ? this.$namespace() + '/' : '') + this.$baseEntity() } From c8deb3e884330d1640ee296360f93e16e419993f Mon Sep 17 00:00:00 2001 From: Gregor Becker Date: Fri, 8 Sep 2023 15:48:55 +0200 Subject: [PATCH 03/10] ci(pinia-orm): change build:ci to build --- .github/workflows/ci.yml | 8 ++++---- package.json | 1 - packages/nuxt/package.json | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cf2633118..a77dfd2b6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,7 +32,7 @@ jobs: - run: pnpm i - - run: pnpm run build:ci + - run: pnpm run build - name: Run unit tests run: pnpm run test @@ -52,7 +52,7 @@ jobs: - run: pnpm i - - run: pnpm run build:ci + - run: pnpm run build - name: Run test coverage run: pnpm run test:coverage @@ -78,7 +78,7 @@ jobs: - run: pnpm i - - run: pnpm run build:ci + - run: pnpm run build - name: Run eslint run: pnpm run lint @@ -99,5 +99,5 @@ jobs: node-version: 18.x - run: pnpm i - - run: pnpm run build:ci + - run: pnpm run build - run: pnpm run size diff --git a/package.json b/package.json index d2d60264b..bc63093eb 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,6 @@ "size": "lerna run size --scope pinia-orm", "build": "pnpm --filter './packages/**' build", "sponsor": "sponsorkit", - "build:ci": "lerna run build --ignore @pina-orm/playground-* --ignore @pinia-orm/nuxt", "build:pinia-orm": "lerna run build --scope pinia-orm", "play": "lerna run play", "build:dts": "lerna run build:dts --parallel", diff --git a/packages/nuxt/package.json b/packages/nuxt/package.json index 622ab2d85..cddd3d629 100644 --- a/packages/nuxt/package.json +++ b/packages/nuxt/package.json @@ -31,7 +31,7 @@ "README.md" ], "scripts": { - "build": "nuxt-module-build", + "build": "nuxt-module-build --stub && nuxt-module-build", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . -l @pinia-orm/nuxt -r 1", "dev": "nuxi dev playground", "dev:build": "nuxi build playground", From 70f61e4dbd46f497a737edccee172e4b8f6fee7c Mon Sep 17 00:00:00 2001 From: Gregor Becker Date: Fri, 8 Sep 2023 16:00:50 +0200 Subject: [PATCH 04/10] ci(pinia-orm): change ci build steps --- .github/workflows/ci.yml | 31 +++++++++++++++---------------- packages/nuxt/package.json | 2 +- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a77dfd2b6..b6ce92bc1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,14 +21,16 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 - - - name: Install pnpm - uses: pnpm/action-setup@v2 + - run: corepack enable - name: Set node version to 18 uses: actions/setup-node@v3 with: - node-version: 18.x + node-version: 18 + cache: "pnpm" + + - name: Install pnpm + uses: pnpm/action-setup@v2 - run: pnpm i @@ -41,14 +43,13 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 - - - name: Install pnpm - uses: pnpm/action-setup@v2 + - run: corepack enable - name: Set node version to 18 uses: actions/setup-node@v3 with: - node-version: 18.x + node-version: 18 + cache: "pnpm" - run: pnpm i @@ -67,14 +68,13 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 - - - name: Install pnpm - uses: pnpm/action-setup@v2 + - run: corepack enable - name: Set node version to 18 uses: actions/setup-node@v3 with: - node-version: 18.x + node-version: 18 + cache: "pnpm" - run: pnpm i @@ -89,14 +89,13 @@ jobs: CI_JOB_NUMBER: 1 steps: - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 - - - name: Install pnpm - uses: pnpm/action-setup@v2 + - run: corepack enable - name: Set node version to 18 uses: actions/setup-node@v3 with: - node-version: 18.x + node-version: 18 + cache: "pnpm" - run: pnpm i - run: pnpm run build diff --git a/packages/nuxt/package.json b/packages/nuxt/package.json index cddd3d629..622ab2d85 100644 --- a/packages/nuxt/package.json +++ b/packages/nuxt/package.json @@ -31,7 +31,7 @@ "README.md" ], "scripts": { - "build": "nuxt-module-build --stub && nuxt-module-build", + "build": "nuxt-module-build", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . -l @pinia-orm/nuxt -r 1", "dev": "nuxi dev playground", "dev:build": "nuxi build playground", From 38815406919c5ff133e5c16eece261621986593a Mon Sep 17 00:00:00 2001 From: Gregor Becker Date: Fri, 8 Sep 2023 16:10:12 +0200 Subject: [PATCH 05/10] ci(pinia-orm): add stub build --- .github/workflows/ci.yml | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b6ce92bc1..f5aa893ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,6 +34,7 @@ jobs: - run: pnpm i + - run: pnpm run build:stub - run: pnpm run build - name: Run unit tests @@ -53,6 +54,7 @@ jobs: - run: pnpm i + - run: pnpm run build:stub - run: pnpm run build - name: Run test coverage @@ -78,6 +80,7 @@ jobs: - run: pnpm i + - run: pnpm run build:stub - run: pnpm run build - name: Run eslint @@ -98,5 +101,6 @@ jobs: cache: "pnpm" - run: pnpm i + - run: pnpm run build:stub - run: pnpm run build - run: pnpm run size diff --git a/package.json b/package.json index bc63093eb..95cd5b54a 100644 --- a/package.json +++ b/package.json @@ -6,10 +6,10 @@ "release": "node scripts/release.mjs", "size": "lerna run size --scope pinia-orm", "build": "pnpm --filter './packages/**' build", + "build:stub": "pnpm --filter './packages/**' prepack --stub", "sponsor": "sponsorkit", "build:pinia-orm": "lerna run build --scope pinia-orm", "play": "lerna run play", - "build:dts": "lerna run build:dts --parallel", "format": "prettier -c --parser typescript \"packages/*/{src,__tests__,e2e}/**/*.[jt]s?(x)\"", "format:fix": "pnpm run format --write", "lint": "lerna run lint --ignore @pina-orm/playground-* --ignore @pina-orm/playground-nuxt3", From 252f7f1ef0521003a9a14547ab96891b1d3b0655 Mon Sep 17 00:00:00 2001 From: Gregor Becker Date: Fri, 8 Sep 2023 16:11:30 +0200 Subject: [PATCH 06/10] ci(pinia-orm): fix build stub command --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 95cd5b54a..9fc76537c 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "release": "node scripts/release.mjs", "size": "lerna run size --scope pinia-orm", "build": "pnpm --filter './packages/**' build", - "build:stub": "pnpm --filter './packages/**' prepack --stub", + "build:stub": "pnpm --filter './packages/**' build --stub", "sponsor": "sponsorkit", "build:pinia-orm": "lerna run build --scope pinia-orm", "play": "lerna run play", From baf7ea0b64f2e5df0e7bfcbac1ce17a6c2bbe5c8 Mon Sep 17 00:00:00 2001 From: Gregor Becker Date: Fri, 8 Sep 2023 16:18:57 +0200 Subject: [PATCH 07/10] ci(pinia-orm): fix build prepare command --- .github/workflows/ci.yml | 4 ++++ package.json | 1 + 2 files changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f5aa893ec..769894b86 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,6 +35,7 @@ jobs: - run: pnpm i - run: pnpm run build:stub + - run: pnpm run build:prepare - run: pnpm run build - name: Run unit tests @@ -55,6 +56,7 @@ jobs: - run: pnpm i - run: pnpm run build:stub + - run: pnpm run build:prepare - run: pnpm run build - name: Run test coverage @@ -81,6 +83,7 @@ jobs: - run: pnpm i - run: pnpm run build:stub + - run: pnpm run build:prepare - run: pnpm run build - name: Run eslint @@ -102,5 +105,6 @@ jobs: - run: pnpm i - run: pnpm run build:stub + - run: pnpm run build:prepare - run: pnpm run build - run: pnpm run size diff --git a/package.json b/package.json index 9fc76537c..b98f74345 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "size": "lerna run size --scope pinia-orm", "build": "pnpm --filter './packages/**' build", "build:stub": "pnpm --filter './packages/**' build --stub", + "build:prepare": "pnpm --filter './packages/**' dev:prepare", "sponsor": "sponsorkit", "build:pinia-orm": "lerna run build --scope pinia-orm", "play": "lerna run play", From 86353ef7283cf669ffb4c9d48741bf6be5043c2f Mon Sep 17 00:00:00 2001 From: Gregor Becker Date: Fri, 8 Sep 2023 16:23:10 +0200 Subject: [PATCH 08/10] ci(pinia-orm): fix other commands --- package.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index b98f74345..903f63610 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "packageManager": "pnpm@8.7.1", "scripts": { "release": "node scripts/release.mjs", + "cleanup": "rimraf 'packages/**/node_modules' 'playground/node_modules' 'node_modules'", "size": "lerna run size --scope pinia-orm", "build": "pnpm --filter './packages/**' build", "build:stub": "pnpm --filter './packages/**' build --stub", @@ -13,10 +14,10 @@ "play": "lerna run play", "format": "prettier -c --parser typescript \"packages/*/{src,__tests__,e2e}/**/*.[jt]s?(x)\"", "format:fix": "pnpm run format --write", - "lint": "lerna run lint --ignore @pina-orm/playground-* --ignore @pina-orm/playground-nuxt3", + "lint": "pnpm --filter './packages/**' lint", "lint:fix": "lerna run lint:fix --ignore @pina-orm/playground-* --ignore @pina-orm/playground-nuxt3", - "test": "lerna run test --scope pinia-orm", - "test:coverage": "lerna run coverage --scope pinia-orm", + "test": "pnpm --filter './packages/**' test", + "test:coverage": "pnpm --filter './packages/**' coverage", "test:types": "tsc --build ./tsconfig.json", "test:dts": "lerna run test:dts", "docs:api": "lerna run docs:api --scope @pinia/docs" From 30e1de0f9959e2cb9faf0c286da50d0c069aa31b Mon Sep 17 00:00:00 2001 From: Gregor Becker Date: Fri, 8 Sep 2023 16:24:17 +0200 Subject: [PATCH 09/10] ci(pinia-orm): change size command --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 903f63610..3339ed033 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "release": "node scripts/release.mjs", "cleanup": "rimraf 'packages/**/node_modules' 'playground/node_modules' 'node_modules'", - "size": "lerna run size --scope pinia-orm", + "size": "pnpm --filter './packages/**' size", "build": "pnpm --filter './packages/**' build", "build:stub": "pnpm --filter './packages/**' build --stub", "build:prepare": "pnpm --filter './packages/**' dev:prepare", From 9c568fc4134e312d50f7f8a127393555f71deb13 Mon Sep 17 00:00:00 2001 From: Gregor Becker Date: Fri, 8 Sep 2023 16:28:38 +0200 Subject: [PATCH 10/10] refactor(pinia-orm): linting --- package.json | 2 +- packages/nuxt/src/runtime/plugin.vue2.ts | 1 - packages/nuxt/src/runtime/plugin.vue3.ts | 1 - packages/pinia-orm/build.config.ts | 4 ++-- packages/pinia-orm/src/store/Config.ts | 4 ++-- .../tests/feature/repository/retrieves_has_or.spec.ts | 2 -- 6 files changed, 5 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 3339ed033..e66f71ead 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "format": "prettier -c --parser typescript \"packages/*/{src,__tests__,e2e}/**/*.[jt]s?(x)\"", "format:fix": "pnpm run format --write", "lint": "pnpm --filter './packages/**' lint", - "lint:fix": "lerna run lint:fix --ignore @pina-orm/playground-* --ignore @pina-orm/playground-nuxt3", + "lint:fix": "pnpm --filter './packages/**' lint:fix", "test": "pnpm --filter './packages/**' test", "test:coverage": "pnpm --filter './packages/**' coverage", "test:types": "tsc --build ./tsconfig.json", diff --git a/packages/nuxt/src/runtime/plugin.vue2.ts b/packages/nuxt/src/runtime/plugin.vue2.ts index 8acc455b2..fb65ef48c 100644 --- a/packages/nuxt/src/runtime/plugin.vue2.ts +++ b/packages/nuxt/src/runtime/plugin.vue2.ts @@ -2,6 +2,5 @@ import { createORM } from 'pinia-orm' import { ormOptions } from '#build/orm-options' export default function (ctx: any) { - // eslint-disable-next-line import/no-named-as-default-member ctx.$pinia.use(createORM(ormOptions)) } diff --git a/packages/nuxt/src/runtime/plugin.vue3.ts b/packages/nuxt/src/runtime/plugin.vue3.ts index 4b83243a2..269ab374b 100644 --- a/packages/nuxt/src/runtime/plugin.vue3.ts +++ b/packages/nuxt/src/runtime/plugin.vue3.ts @@ -4,7 +4,6 @@ import { defineNuxtPlugin } from '#app' import { ormOptions } from '#build/orm-options' export default defineNuxtPlugin((nuxtApp) => { - // eslint-disable-next-line import/no-named-as-default-member nuxtApp.$pinia.use(createORM(ormOptions)) setActivePinia(nuxtApp.$pinia) }) diff --git a/packages/pinia-orm/build.config.ts b/packages/pinia-orm/build.config.ts index ecd02f8b2..01b4e28ff 100644 --- a/packages/pinia-orm/build.config.ts +++ b/packages/pinia-orm/build.config.ts @@ -1,5 +1,5 @@ // build.config.ts -import fs from 'node:fs' +// import fs from 'node:fs' import { defineBuildConfig } from 'unbuild' export default defineBuildConfig({ @@ -21,7 +21,7 @@ export default defineBuildConfig({ externals: ['@/composables', 'nanoid', 'uuid', 'nanoid/async', 'nanoid/non-secure', 'pinia'], rollup: { emitCJS: true - }, + } // hooks: { // 'build:done': (ctx) => { // ctx.buildEntries.filter(entry => entry.path.includes('.cjs') && !entry.path.includes('shared')).forEach((entry) => { diff --git a/packages/pinia-orm/src/store/Config.ts b/packages/pinia-orm/src/store/Config.ts index 6ae236215..0f6aab730 100644 --- a/packages/pinia-orm/src/store/Config.ts +++ b/packages/pinia-orm/src/store/Config.ts @@ -6,12 +6,12 @@ export const CONFIG_DEFAULTS = { namespace: '', withMeta: false, hidden: ['_meta'], - visible: ['*'], + visible: ['*'] }, cache: { shared: true, provider: WeakCache - }, + } } export const config: FilledInstallOptions = { ...CONFIG_DEFAULTS } diff --git a/packages/pinia-orm/tests/feature/repository/retrieves_has_or.spec.ts b/packages/pinia-orm/tests/feature/repository/retrieves_has_or.spec.ts index f00754fc8..574806318 100644 --- a/packages/pinia-orm/tests/feature/repository/retrieves_has_or.spec.ts +++ b/packages/pinia-orm/tests/feature/repository/retrieves_has_or.spec.ts @@ -112,8 +112,6 @@ describe('feature/repository/retrieves_has_or', () => { { id: 3, name: 'Johnny Doe' } ] - - expect(users).toHaveLength(2) expect(users2).toHaveLength(3) assertInstanceOf(users, User)