Skip to content

Commit

Permalink
- First version of core model
Browse files Browse the repository at this point in the history
  • Loading branch information
alvaro-canepa committed Jan 7, 2024
1 parent 1afa2ec commit 099ce1a
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 24 deletions.
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"extends": ["eslint-config-unjs"],
"rules": {}
"rules": {
"unicorn/filename-case": "off",
"@typescript-eslint/consistent-type-imports": "error"
}
}
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18
24 changes: 8 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,40 @@
# packageName
# @planetadeleste/pinia-orm-core

[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![bundle][bundle-src]][bundle-href]
[![Codecov][codecov-src]][codecov-href]

This is my package description.
Model extends [pinia-orm](https://github.com/CodeDredd/pinia-orm) base model

## Usage

Install package:

```sh
# npm
npm install packageName
npm install @planetadeleste/pinia-orm-core

# yarn
yarn add packageName
yarn add @planetadeleste/pinia-orm-core

# pnpm
pnpm install packageName
pnpm install @planetadeleste/pinia-orm-core

# bun
bun install packageName
bun install @planetadeleste/pinia-orm-core
```

Import:

```js
// ESM
import {} from "packageName";
import Model from "@planetadeleste/pinia-orm-core";

// CommonJS
const {} = require("packageName");
const Model = require("@planetadeleste/pinia-orm-core");
```

## Development

- Clone this repository
- Install latest LTS version of [Node.js](https://nodejs.org/en/)
- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable`
- Install dependencies using `pnpm install`
- Run interactive tests using `pnpm dev`

## License

Made with 💛
Expand Down
19 changes: 15 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"name": "packageName",
"version": "0.0.0",
"name": "@planetadeleste/pinia-orm-core",
"version": "1.0.0",
"description": "",
"repository": "unjs/packageName",
"repository":{
"type": "git",
"url": "git+https://github.com/planetadeleste/pinia-orm-core.git"
},
"license": "MIT",
"sideEffects": false,
"type": "module",
Expand Down Expand Up @@ -31,7 +34,9 @@
"test:types": "tsc --noEmit --skipLibCheck"
},
"devDependencies": {
"@types/lodash": "^4.14.202",
"@types/node": "^20.10.5",
"@types/uuid": "^9.0.7",
"@vitest/coverage-v8": "^1.1.0",
"changelogen": "^0.5.5",
"eslint": "^8.56.0",
Expand All @@ -42,5 +47,11 @@
"unbuild": "^2.0.0",
"vitest": "^1.1.0"
},
"packageManager": "[email protected]"
"packageManager": "[email protected]",
"dependencies": {
"lodash": "^4.17.21",
"pinia": "^2.1.7",
"pinia-orm": "^1.7.2",
"uuid": "^9.0.1"
}
}
28 changes: 28 additions & 0 deletions src/Model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { isEmpty, startsWith } from "lodash";
import type { Element } from "pinia-orm";
import { Model as BaseModel } from "pinia-orm";
import { v4 } from "uuid";

interface Model<T extends Element = Element> extends BaseModel {
id: string | number;
created_at?: string;
updated_at?: string;
uuid: boolean;
}

class Model<T extends Element = Element> extends BaseModel {
static baseUrl: string;
static uuid = false;

static creating<M extends Model = Model>(model: M) {
if (model.uuid && isEmpty(model.$getIndexId())) {
model.id = `-${v4()}`;
}
}

$isNew(): boolean {
return !this.id || startsWith(this.id as string, "-") || !this.created_at;
}
}

export default Model;
4 changes: 1 addition & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export function test() {
return "works!";
}
export { default as Model } from "./Model";

0 comments on commit 099ce1a

Please sign in to comment.