pinia-orm-edge 1.7.3-28257628.bbb8bab
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +96 -0
- package/dist/casts.cjs +124 -0
- package/dist/casts.d.cts +66 -0
- package/dist/casts.d.mts +66 -0
- package/dist/casts.d.ts +66 -0
- package/dist/casts.mjs +118 -0
- package/dist/decorators.cjs +219 -0
- package/dist/decorators.d.cts +107 -0
- package/dist/decorators.d.mts +107 -0
- package/dist/decorators.d.ts +107 -0
- package/dist/decorators.mjs +198 -0
- package/dist/helpers.cjs +69 -0
- package/dist/helpers.d.cts +54 -0
- package/dist/helpers.d.mts +54 -0
- package/dist/helpers.d.ts +54 -0
- package/dist/helpers.mjs +61 -0
- package/dist/index.cjs +3592 -0
- package/dist/index.d.cts +49 -0
- package/dist/index.d.mts +49 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.mjs +3561 -0
- package/dist/nanoid/async.cjs +42 -0
- package/dist/nanoid/async.d.cts +29 -0
- package/dist/nanoid/async.d.mts +29 -0
- package/dist/nanoid/async.d.ts +29 -0
- package/dist/nanoid/async.mjs +39 -0
- package/dist/nanoid/index.cjs +42 -0
- package/dist/nanoid/index.d.cts +24 -0
- package/dist/nanoid/index.d.mts +24 -0
- package/dist/nanoid/index.d.ts +24 -0
- package/dist/nanoid/index.mjs +39 -0
- package/dist/nanoid/non-secure.cjs +42 -0
- package/dist/nanoid/non-secure.d.cts +24 -0
- package/dist/nanoid/non-secure.d.mts +24 -0
- package/dist/nanoid/non-secure.d.ts +24 -0
- package/dist/nanoid/non-secure.mjs +39 -0
- package/dist/shared/pinia-orm.1bd7d299.mjs +153 -0
- package/dist/shared/pinia-orm.4ff2e12f.mjs +66 -0
- package/dist/shared/pinia-orm.876a7cdc.d.cts +1981 -0
- package/dist/shared/pinia-orm.876a7cdc.d.mts +1981 -0
- package/dist/shared/pinia-orm.876a7cdc.d.ts +1981 -0
- package/dist/shared/pinia-orm.a62c4fc4.cjs +167 -0
- package/dist/shared/pinia-orm.a7e3e0f3.cjs +68 -0
- package/dist/uuid/v1.cjs +41 -0
- package/dist/uuid/v1.d.cts +25 -0
- package/dist/uuid/v1.d.mts +25 -0
- package/dist/uuid/v1.d.ts +25 -0
- package/dist/uuid/v1.mjs +38 -0
- package/dist/uuid/v4.cjs +41 -0
- package/dist/uuid/v4.d.cts +25 -0
- package/dist/uuid/v4.d.mts +25 -0
- package/dist/uuid/v4.d.ts +25 -0
- package/dist/uuid/v4.mjs +38 -0
- package/package.json +126 -0
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022-present Gregor Becker
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
[](https://github.com/storm-tail/pinia-orm)
|
2
|
+
|
3
|
+
[![npm version][npm-version-src]][npm-version-href]
|
4
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
5
|
+
[![Github Actions CI][github-actions-ci-src]][github-actions-ci-href]
|
6
|
+
[![Coverage][code-coverage-src]][code-coverage-href]
|
7
|
+
[![License][license-src]][license-href]
|
8
|
+
|
9
|
+
# Welcome to pinia-orm
|
10
|
+
|
11
|
+
> Intuitive, type safe and flexible ORM for Pinia based on [Vuex ORM Next](https://github.com/vuex-orm/vuex-orm-next)
|
12
|
+
|
13
|
+
- [✨ Release Notes](https://pinia-orm.codedredd.de/changelog)
|
14
|
+
- [📖 Documentation](https://pinia-orm.codedredd.de)
|
15
|
+
- [👾 Playground](https://pinia-orm-play.codedredd.de)
|
16
|
+
|
17
|
+
## Migration from vuex-orm
|
18
|
+
|
19
|
+
You want to migrate from vuex to pinia and with it vuex-orm to pinia-orm but you don't know yet?
|
20
|
+
Well maybe this table will help you to decide. This comparison is just about facts and current state.
|
21
|
+
|
22
|
+
| Features | pinia-orm@v1.4.0 | @vuex-orm/core@0.36.4 | @vuex-orm/core@1.0.0-draft.16 |
|
23
|
+
|------------------------------------------------------------------------|------------------------------------------------------------| ----------------------------------------------------------------- | ------------------------------------------------------------------------- |
|
24
|
+
| Bundle Size (Min + GZIP) | [9.9 KB](https://bundlephobia.com/package/pinia-orm@1.4.0) | [16.7 KB](https://bundlephobia.com/package/@vuex-orm/core@0.36.4) | [12.6 KB](https://bundlephobia.com/package/@vuex-orm/core@1.0.0-draft.16) |
|
25
|
+
| Relations (hasMany, belongsTo, morphOne, hasManyBy, hasOne, morphTo) | ✅ | ✅ | ✅ |
|
26
|
+
| Relations (morphMany, belongsToMany, hasManyThrough) | ✅ | ✅ | ❌ |
|
27
|
+
| Relations (morphToMany, morphedByMany) | ❌ | ✅ | ❌ |
|
28
|
+
| Mutators | ✅ | ✅ | ❌ |
|
29
|
+
| Casts | ✅ | ❌ | ❌ |
|
30
|
+
| Decorators | ✅ | ❌ | ✅ |
|
31
|
+
| Single Table Inheritance | ✅ | ✅ | ❌ |
|
32
|
+
| Lifecycle Hooks | ✅ | ✅ | ❌ |
|
33
|
+
| Aggregates | ✅ | ✅ | ❌ |
|
34
|
+
| Query (orHas, doesntHave, orDoesntHave, whereHas, orWhereHas, groupBy) | ✅ | ❌ | ❌ |
|
35
|
+
| Collection Helpers | ✅ | (✅) can use pinia-orm helpers too | (✅) can use pinia-orm helpers too |
|
36
|
+
| Hidden Fields | ✅ | ❌ | ❌ |
|
37
|
+
| Metadata field | ✅ | ❌ | ❌ |
|
38
|
+
| Caching of queries with gc | ✅ | (✅) with plugin | ❌ |
|
39
|
+
|
40
|
+
If you decide to migrate then there are some breaking changes. A guide how to migrate will be written.
|
41
|
+
Small overview:
|
42
|
+
|
43
|
+
- Fields are by default `null`
|
44
|
+
- Renamed some functions aligning more with laravel naming
|
45
|
+
- Code is based on `vuex-orm-next` and not on `vuex-orm` !
|
46
|
+
|
47
|
+
## Help me keep working on this project 💚
|
48
|
+
|
49
|
+
- [Become a Sponsor on GitHub](https://github.com/sponsors/codedredd)
|
50
|
+
- [One-time donation via PayPal](https://paypal.me/dredd1984)
|
51
|
+
|
52
|
+
<p align="center">
|
53
|
+
<a href="https://pinia-orm.codedredd.de/sponsorkit/sponsors.png">
|
54
|
+
<img src='https://pinia-orm.codedredd.de/sponsorkit/sponsors.svg'/>
|
55
|
+
</a>
|
56
|
+
</p>
|
57
|
+
|
58
|
+
---
|
59
|
+
|
60
|
+
## 💻 Development
|
61
|
+
|
62
|
+
- Clone this repository
|
63
|
+
- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable` (use `npm i -g corepack` for Node.js < 16.10)
|
64
|
+
- Install dependencies using `pnpm install`
|
65
|
+
- Build normalizr package: `pnpm build`
|
66
|
+
- Run interactive tests using `cd packages/pinia-orm && pnpm test:ui`
|
67
|
+
|
68
|
+
## Credits
|
69
|
+
|
70
|
+
- [Kia King Ishii](https://github.com/kiaking)
|
71
|
+
- [Cuebit](https://github.com/cuebit)
|
72
|
+
- [Posva](https://github.com/posva)
|
73
|
+
|
74
|
+
## Related projects
|
75
|
+
|
76
|
+
- [Vuex ORM](https://github.com/vuex-orm/vuex-orm)
|
77
|
+
- [Vuex ORM Next](https://github.com/vuex-orm/vuex-orm-next)
|
78
|
+
|
79
|
+
## License
|
80
|
+
|
81
|
+
Made with ❤️
|
82
|
+
|
83
|
+
Published under [MIT License](./LICENCE).
|
84
|
+
|
85
|
+
<!-- Badges -->
|
86
|
+
|
87
|
+
[npm-version-src]: https://img.shields.io/npm/v/pinia-orm/latest.svg
|
88
|
+
[code-coverage-src]: https://img.shields.io/codecov/c/github/CodeDredd/pinia-orm?logo=Codecov&logoColor=white&token=BYLAJJOOLS
|
89
|
+
[code-coverage-href]: https://app.codecov.io/gh/CodeDredd/pinia-orm
|
90
|
+
[npm-version-href]: https://npmjs.com/package/pinia-orm
|
91
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/pinia-orm.svg
|
92
|
+
[npm-downloads-href]: https://npmjs.com/package/pinia-orm
|
93
|
+
[github-actions-ci-src]: https://github.com/codedredd/pinia-orm/actions/workflows/ci.yml/badge.svg
|
94
|
+
[github-actions-ci-href]: https://github.com/codedredd/pinia-orm/actions?query=workflow%3Aci
|
95
|
+
[license-src]: https://img.shields.io/npm/l/pinia-orm.svg
|
96
|
+
[license-href]: https://npmjs.com/package/pinia-orm
|
package/dist/casts.cjs
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const CastAttribute = require('./shared/pinia-orm.a7e3e0f3.cjs');
|
4
|
+
|
5
|
+
class ArrayCast extends CastAttribute.CastAttribute {
|
6
|
+
/**
|
7
|
+
* Create a new String attribute instance.
|
8
|
+
*/
|
9
|
+
constructor(attributes) {
|
10
|
+
super(attributes);
|
11
|
+
}
|
12
|
+
get(value) {
|
13
|
+
return typeof value !== "string" ? value : JSON.parse(value);
|
14
|
+
}
|
15
|
+
/**
|
16
|
+
* Make the value for the attribute.
|
17
|
+
*/
|
18
|
+
set(value) {
|
19
|
+
return JSON.stringify(value);
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
class StringCast extends CastAttribute.CastAttribute {
|
24
|
+
/**
|
25
|
+
* Create a new String attribute instance.
|
26
|
+
*/
|
27
|
+
constructor(attributes) {
|
28
|
+
super(attributes);
|
29
|
+
}
|
30
|
+
get(value) {
|
31
|
+
return typeof value === "string" || value === void 0 || value === null ? value : `${value}`;
|
32
|
+
}
|
33
|
+
/**
|
34
|
+
* Make the value for the attribute.
|
35
|
+
*/
|
36
|
+
set(value) {
|
37
|
+
return this.get(value);
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
class BooleanCast extends CastAttribute.CastAttribute {
|
42
|
+
/**
|
43
|
+
* Create a new String attribute instance.
|
44
|
+
*/
|
45
|
+
constructor(attributes) {
|
46
|
+
super(attributes);
|
47
|
+
}
|
48
|
+
get(value) {
|
49
|
+
if (typeof value === "boolean" || value === void 0 || value === null) {
|
50
|
+
return value;
|
51
|
+
}
|
52
|
+
if (typeof value === "string") {
|
53
|
+
if (value.length === 0) {
|
54
|
+
return false;
|
55
|
+
}
|
56
|
+
const int = Number.parseInt(value, 0);
|
57
|
+
return Number.isNaN(int) ? true : !!int;
|
58
|
+
}
|
59
|
+
if (typeof value === "number") {
|
60
|
+
return !!value;
|
61
|
+
}
|
62
|
+
return false;
|
63
|
+
}
|
64
|
+
/**
|
65
|
+
* Make the value for the attribute.
|
66
|
+
*/
|
67
|
+
set(value) {
|
68
|
+
return this.get(value);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
class NumberCast extends CastAttribute.CastAttribute {
|
73
|
+
/**
|
74
|
+
* Create a new String attribute instance.
|
75
|
+
*/
|
76
|
+
constructor(attributes) {
|
77
|
+
super(attributes);
|
78
|
+
}
|
79
|
+
get(value) {
|
80
|
+
if (typeof value === "number" || value === void 0 || value === null) {
|
81
|
+
return value;
|
82
|
+
}
|
83
|
+
if (typeof value === "string") {
|
84
|
+
return Number.parseFloat(value);
|
85
|
+
}
|
86
|
+
if (typeof value === "boolean") {
|
87
|
+
return value ? 1 : 0;
|
88
|
+
}
|
89
|
+
return 0;
|
90
|
+
}
|
91
|
+
/**
|
92
|
+
* Make the value for the attribute.
|
93
|
+
*/
|
94
|
+
set(value) {
|
95
|
+
return this.get(value);
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
99
|
+
class DateCast extends CastAttribute.CastAttribute {
|
100
|
+
/**
|
101
|
+
* Create a new String attribute instance.
|
102
|
+
*/
|
103
|
+
constructor(attributes) {
|
104
|
+
super(attributes);
|
105
|
+
}
|
106
|
+
get(value) {
|
107
|
+
return value === null ? null : new Date(value);
|
108
|
+
}
|
109
|
+
/**
|
110
|
+
* Make the value for the attribute.
|
111
|
+
*/
|
112
|
+
set(value) {
|
113
|
+
if (value === null) {
|
114
|
+
return null;
|
115
|
+
}
|
116
|
+
return (typeof value === "string" ? new Date(Date.parse(value)) : value).toISOString();
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
exports.ArrayCast = ArrayCast;
|
121
|
+
exports.BooleanCast = BooleanCast;
|
122
|
+
exports.DateCast = DateCast;
|
123
|
+
exports.NumberCast = NumberCast;
|
124
|
+
exports.StringCast = StringCast;
|
package/dist/casts.d.cts
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
import { $ as CastAttribute, m as ModelFields } from './shared/pinia-orm.876a7cdc.cjs';
|
2
|
+
import 'pinia';
|
3
|
+
import '@pinia-orm/normalizr';
|
4
|
+
import '@/composables';
|
5
|
+
|
6
|
+
declare class ArrayCast extends CastAttribute {
|
7
|
+
/**
|
8
|
+
* Create a new String attribute instance.
|
9
|
+
*/
|
10
|
+
constructor(attributes: ModelFields);
|
11
|
+
get(value?: any): any;
|
12
|
+
/**
|
13
|
+
* Make the value for the attribute.
|
14
|
+
*/
|
15
|
+
set(value: any): string | null;
|
16
|
+
}
|
17
|
+
|
18
|
+
declare class StringCast extends CastAttribute {
|
19
|
+
/**
|
20
|
+
* Create a new String attribute instance.
|
21
|
+
*/
|
22
|
+
constructor(attributes: ModelFields);
|
23
|
+
get(value?: any): any;
|
24
|
+
/**
|
25
|
+
* Make the value for the attribute.
|
26
|
+
*/
|
27
|
+
set(value: any): string | null;
|
28
|
+
}
|
29
|
+
|
30
|
+
declare class BooleanCast extends CastAttribute {
|
31
|
+
/**
|
32
|
+
* Create a new String attribute instance.
|
33
|
+
*/
|
34
|
+
constructor(attributes: ModelFields);
|
35
|
+
get(value?: any): any;
|
36
|
+
/**
|
37
|
+
* Make the value for the attribute.
|
38
|
+
*/
|
39
|
+
set(value: any): string | null;
|
40
|
+
}
|
41
|
+
|
42
|
+
declare class NumberCast extends CastAttribute {
|
43
|
+
/**
|
44
|
+
* Create a new String attribute instance.
|
45
|
+
*/
|
46
|
+
constructor(attributes: ModelFields);
|
47
|
+
get(value?: any): any;
|
48
|
+
/**
|
49
|
+
* Make the value for the attribute.
|
50
|
+
*/
|
51
|
+
set(value: any): string | null;
|
52
|
+
}
|
53
|
+
|
54
|
+
declare class DateCast extends CastAttribute {
|
55
|
+
/**
|
56
|
+
* Create a new String attribute instance.
|
57
|
+
*/
|
58
|
+
constructor(attributes: ModelFields);
|
59
|
+
get(value: string | null): Date | null;
|
60
|
+
/**
|
61
|
+
* Make the value for the attribute.
|
62
|
+
*/
|
63
|
+
set(value: string | Date | null): string | null;
|
64
|
+
}
|
65
|
+
|
66
|
+
export { ArrayCast, BooleanCast, DateCast, NumberCast, StringCast };
|
package/dist/casts.d.mts
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
import { $ as CastAttribute, m as ModelFields } from './shared/pinia-orm.876a7cdc.mjs';
|
2
|
+
import 'pinia';
|
3
|
+
import '@pinia-orm/normalizr';
|
4
|
+
import '@/composables';
|
5
|
+
|
6
|
+
declare class ArrayCast extends CastAttribute {
|
7
|
+
/**
|
8
|
+
* Create a new String attribute instance.
|
9
|
+
*/
|
10
|
+
constructor(attributes: ModelFields);
|
11
|
+
get(value?: any): any;
|
12
|
+
/**
|
13
|
+
* Make the value for the attribute.
|
14
|
+
*/
|
15
|
+
set(value: any): string | null;
|
16
|
+
}
|
17
|
+
|
18
|
+
declare class StringCast extends CastAttribute {
|
19
|
+
/**
|
20
|
+
* Create a new String attribute instance.
|
21
|
+
*/
|
22
|
+
constructor(attributes: ModelFields);
|
23
|
+
get(value?: any): any;
|
24
|
+
/**
|
25
|
+
* Make the value for the attribute.
|
26
|
+
*/
|
27
|
+
set(value: any): string | null;
|
28
|
+
}
|
29
|
+
|
30
|
+
declare class BooleanCast extends CastAttribute {
|
31
|
+
/**
|
32
|
+
* Create a new String attribute instance.
|
33
|
+
*/
|
34
|
+
constructor(attributes: ModelFields);
|
35
|
+
get(value?: any): any;
|
36
|
+
/**
|
37
|
+
* Make the value for the attribute.
|
38
|
+
*/
|
39
|
+
set(value: any): string | null;
|
40
|
+
}
|
41
|
+
|
42
|
+
declare class NumberCast extends CastAttribute {
|
43
|
+
/**
|
44
|
+
* Create a new String attribute instance.
|
45
|
+
*/
|
46
|
+
constructor(attributes: ModelFields);
|
47
|
+
get(value?: any): any;
|
48
|
+
/**
|
49
|
+
* Make the value for the attribute.
|
50
|
+
*/
|
51
|
+
set(value: any): string | null;
|
52
|
+
}
|
53
|
+
|
54
|
+
declare class DateCast extends CastAttribute {
|
55
|
+
/**
|
56
|
+
* Create a new String attribute instance.
|
57
|
+
*/
|
58
|
+
constructor(attributes: ModelFields);
|
59
|
+
get(value: string | null): Date | null;
|
60
|
+
/**
|
61
|
+
* Make the value for the attribute.
|
62
|
+
*/
|
63
|
+
set(value: string | Date | null): string | null;
|
64
|
+
}
|
65
|
+
|
66
|
+
export { ArrayCast, BooleanCast, DateCast, NumberCast, StringCast };
|
package/dist/casts.d.ts
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
import { $ as CastAttribute, m as ModelFields } from './shared/pinia-orm.876a7cdc.js';
|
2
|
+
import 'pinia';
|
3
|
+
import '@pinia-orm/normalizr';
|
4
|
+
import '@/composables';
|
5
|
+
|
6
|
+
declare class ArrayCast extends CastAttribute {
|
7
|
+
/**
|
8
|
+
* Create a new String attribute instance.
|
9
|
+
*/
|
10
|
+
constructor(attributes: ModelFields);
|
11
|
+
get(value?: any): any;
|
12
|
+
/**
|
13
|
+
* Make the value for the attribute.
|
14
|
+
*/
|
15
|
+
set(value: any): string | null;
|
16
|
+
}
|
17
|
+
|
18
|
+
declare class StringCast extends CastAttribute {
|
19
|
+
/**
|
20
|
+
* Create a new String attribute instance.
|
21
|
+
*/
|
22
|
+
constructor(attributes: ModelFields);
|
23
|
+
get(value?: any): any;
|
24
|
+
/**
|
25
|
+
* Make the value for the attribute.
|
26
|
+
*/
|
27
|
+
set(value: any): string | null;
|
28
|
+
}
|
29
|
+
|
30
|
+
declare class BooleanCast extends CastAttribute {
|
31
|
+
/**
|
32
|
+
* Create a new String attribute instance.
|
33
|
+
*/
|
34
|
+
constructor(attributes: ModelFields);
|
35
|
+
get(value?: any): any;
|
36
|
+
/**
|
37
|
+
* Make the value for the attribute.
|
38
|
+
*/
|
39
|
+
set(value: any): string | null;
|
40
|
+
}
|
41
|
+
|
42
|
+
declare class NumberCast extends CastAttribute {
|
43
|
+
/**
|
44
|
+
* Create a new String attribute instance.
|
45
|
+
*/
|
46
|
+
constructor(attributes: ModelFields);
|
47
|
+
get(value?: any): any;
|
48
|
+
/**
|
49
|
+
* Make the value for the attribute.
|
50
|
+
*/
|
51
|
+
set(value: any): string | null;
|
52
|
+
}
|
53
|
+
|
54
|
+
declare class DateCast extends CastAttribute {
|
55
|
+
/**
|
56
|
+
* Create a new String attribute instance.
|
57
|
+
*/
|
58
|
+
constructor(attributes: ModelFields);
|
59
|
+
get(value: string | null): Date | null;
|
60
|
+
/**
|
61
|
+
* Make the value for the attribute.
|
62
|
+
*/
|
63
|
+
set(value: string | Date | null): string | null;
|
64
|
+
}
|
65
|
+
|
66
|
+
export { ArrayCast, BooleanCast, DateCast, NumberCast, StringCast };
|
package/dist/casts.mjs
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
import { C as CastAttribute } from './shared/pinia-orm.4ff2e12f.mjs';
|
2
|
+
|
3
|
+
class ArrayCast extends CastAttribute {
|
4
|
+
/**
|
5
|
+
* Create a new String attribute instance.
|
6
|
+
*/
|
7
|
+
constructor(attributes) {
|
8
|
+
super(attributes);
|
9
|
+
}
|
10
|
+
get(value) {
|
11
|
+
return typeof value !== "string" ? value : JSON.parse(value);
|
12
|
+
}
|
13
|
+
/**
|
14
|
+
* Make the value for the attribute.
|
15
|
+
*/
|
16
|
+
set(value) {
|
17
|
+
return JSON.stringify(value);
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
class StringCast extends CastAttribute {
|
22
|
+
/**
|
23
|
+
* Create a new String attribute instance.
|
24
|
+
*/
|
25
|
+
constructor(attributes) {
|
26
|
+
super(attributes);
|
27
|
+
}
|
28
|
+
get(value) {
|
29
|
+
return typeof value === "string" || value === void 0 || value === null ? value : `${value}`;
|
30
|
+
}
|
31
|
+
/**
|
32
|
+
* Make the value for the attribute.
|
33
|
+
*/
|
34
|
+
set(value) {
|
35
|
+
return this.get(value);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
class BooleanCast extends CastAttribute {
|
40
|
+
/**
|
41
|
+
* Create a new String attribute instance.
|
42
|
+
*/
|
43
|
+
constructor(attributes) {
|
44
|
+
super(attributes);
|
45
|
+
}
|
46
|
+
get(value) {
|
47
|
+
if (typeof value === "boolean" || value === void 0 || value === null) {
|
48
|
+
return value;
|
49
|
+
}
|
50
|
+
if (typeof value === "string") {
|
51
|
+
if (value.length === 0) {
|
52
|
+
return false;
|
53
|
+
}
|
54
|
+
const int = Number.parseInt(value, 0);
|
55
|
+
return Number.isNaN(int) ? true : !!int;
|
56
|
+
}
|
57
|
+
if (typeof value === "number") {
|
58
|
+
return !!value;
|
59
|
+
}
|
60
|
+
return false;
|
61
|
+
}
|
62
|
+
/**
|
63
|
+
* Make the value for the attribute.
|
64
|
+
*/
|
65
|
+
set(value) {
|
66
|
+
return this.get(value);
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
class NumberCast extends CastAttribute {
|
71
|
+
/**
|
72
|
+
* Create a new String attribute instance.
|
73
|
+
*/
|
74
|
+
constructor(attributes) {
|
75
|
+
super(attributes);
|
76
|
+
}
|
77
|
+
get(value) {
|
78
|
+
if (typeof value === "number" || value === void 0 || value === null) {
|
79
|
+
return value;
|
80
|
+
}
|
81
|
+
if (typeof value === "string") {
|
82
|
+
return Number.parseFloat(value);
|
83
|
+
}
|
84
|
+
if (typeof value === "boolean") {
|
85
|
+
return value ? 1 : 0;
|
86
|
+
}
|
87
|
+
return 0;
|
88
|
+
}
|
89
|
+
/**
|
90
|
+
* Make the value for the attribute.
|
91
|
+
*/
|
92
|
+
set(value) {
|
93
|
+
return this.get(value);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
class DateCast extends CastAttribute {
|
98
|
+
/**
|
99
|
+
* Create a new String attribute instance.
|
100
|
+
*/
|
101
|
+
constructor(attributes) {
|
102
|
+
super(attributes);
|
103
|
+
}
|
104
|
+
get(value) {
|
105
|
+
return value === null ? null : new Date(value);
|
106
|
+
}
|
107
|
+
/**
|
108
|
+
* Make the value for the attribute.
|
109
|
+
*/
|
110
|
+
set(value) {
|
111
|
+
if (value === null) {
|
112
|
+
return null;
|
113
|
+
}
|
114
|
+
return (typeof value === "string" ? new Date(Date.parse(value)) : value).toISOString();
|
115
|
+
}
|
116
|
+
}
|
117
|
+
|
118
|
+
export { ArrayCast, BooleanCast, DateCast, NumberCast, StringCast };
|