Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): allow using Ref wrapper on scalar properties #4358

Merged
merged 1 commit into from May 24, 2023
Merged

Conversation

B4nan
Copy link
Member

@B4nan B4nan commented May 15, 2023

ScalarReference wrapper

Similarly to the Reference wrapper, we can also wrap scalars with Ref into a ScalarReference object. This is handy for lazy scalar properties.

@Property({ lazy: true, ref: true })
passwordHash!: Ref<string>;

The Ref type automatically resolves to ScalarReference for non-object types. You can use it explicitly if you want to wrap an object scalar property (e.g. JSON value).

const user = await em.findOne(User, 1);
const passwordHash = await user.passwordHash.load();

@codecov
Copy link

codecov bot commented May 15, 2023

Codecov Report

Patch coverage: 98.93% and project coverage change: -0.02 ⚠️

Comparison is base (a2eae78) 99.55% compared to head (9a09d7f) 99.53%.

Additional details and impacted files
@@            Coverage Diff             @@
##               v6    #4358      +/-   ##
==========================================
- Coverage   99.55%   99.53%   -0.02%     
==========================================
  Files         218      218              
  Lines       14670    14722      +52     
  Branches     3386     3399      +13     
==========================================
+ Hits        14604    14653      +49     
- Misses         65       68       +3     
  Partials        1        1              
Impacted Files Coverage Δ
packages/core/src/decorators/Property.ts 100.00% <ø> (ø)
packages/core/src/typings.ts 100.00% <ø> (ø)
packages/core/src/entity/Reference.ts 97.24% <97.56%> (-0.38%) ⬇️
packages/core/src/EntityManager.ts 96.52% <100.00%> (ø)
packages/core/src/entity/EntityLoader.ts 100.00% <100.00%> (ø)
packages/core/src/entity/EntityRepository.ts 96.49% <100.00%> (ø)
packages/core/src/entity/wrap.ts 100.00% <100.00%> (ø)
packages/core/src/hydration/ObjectHydrator.ts 100.00% <100.00%> (ø)
...ackages/core/src/serialization/EntitySerializer.ts 100.00% <100.00%> (ø)
...ckages/core/src/serialization/EntityTransformer.ts 100.00% <100.00%> (ø)
... and 2 more

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@B4nan B4nan marked this pull request as ready for review May 24, 2023 18:12
@B4nan B4nan merged commit 89f759a into v6 May 24, 2023
7 of 9 checks passed
@B4nan B4nan deleted the scalar-refs branch May 24, 2023 18:40
B4nan added a commit that referenced this pull request May 26, 2023
Similarly to the `Reference` wrapper, we can also wrap scalars with
`Ref` into a `ScalarReference` object. This is handy for lazy scalar
properties.

```ts
@Property({ lazy: true, ref: true })
passwordHash!: Ref<string>;
```

The `Ref` type automatically resolves to `ScalarReference` for
non-object types. You can use it explicitly if you want to wrap an
object scalar property (e.g. JSON value).

```ts
const user = await em.findOne(User, 1);
const passwordHash = await user.passwordHash.load();
```
B4nan added a commit that referenced this pull request Jun 11, 2023
Similarly to the `Reference` wrapper, we can also wrap scalars with
`Ref` into a `ScalarReference` object. This is handy for lazy scalar
properties.

```ts
@Property({ lazy: true, ref: true })
passwordHash!: Ref<string>;
```

The `Ref` type automatically resolves to `ScalarReference` for
non-object types. You can use it explicitly if you want to wrap an
object scalar property (e.g. JSON value).

```ts
const user = await em.findOne(User, 1);
const passwordHash = await user.passwordHash.load();
```
B4nan added a commit that referenced this pull request Sep 10, 2023
Similarly to the `Reference` wrapper, we can also wrap scalars with
`Ref` into a `ScalarReference` object. This is handy for lazy scalar
properties.

```ts
@Property({ lazy: true, ref: true })
passwordHash!: Ref<string>;
```

The `Ref` type automatically resolves to `ScalarReference` for
non-object types. You can use it explicitly if you want to wrap an
object scalar property (e.g. JSON value).

```ts
const user = await em.findOne(User, 1);
const passwordHash = await user.passwordHash.load();
```
B4nan added a commit that referenced this pull request Sep 20, 2023
Similarly to the `Reference` wrapper, we can also wrap scalars with
`Ref` into a `ScalarReference` object. This is handy for lazy scalar
properties.

```ts
@Property({ lazy: true, ref: true })
passwordHash!: Ref<string>;
```

The `Ref` type automatically resolves to `ScalarReference` for
non-object types. You can use it explicitly if you want to wrap an
object scalar property (e.g. JSON value).

```ts
const user = await em.findOne(User, 1);
const passwordHash = await user.passwordHash.load();
```
B4nan added a commit that referenced this pull request Sep 24, 2023
Similarly to the `Reference` wrapper, we can also wrap scalars with
`Ref` into a `ScalarReference` object. This is handy for lazy scalar
properties.

```ts
@Property({ lazy: true, ref: true })
passwordHash!: Ref<string>;
```

The `Ref` type automatically resolves to `ScalarReference` for
non-object types. You can use it explicitly if you want to wrap an
object scalar property (e.g. JSON value).

```ts
const user = await em.findOne(User, 1);
const passwordHash = await user.passwordHash.load();
```
B4nan added a commit that referenced this pull request Sep 30, 2023
Similarly to the `Reference` wrapper, we can also wrap scalars with
`Ref` into a `ScalarReference` object. This is handy for lazy scalar
properties.

```ts
@Property({ lazy: true, ref: true })
passwordHash!: Ref<string>;
```

The `Ref` type automatically resolves to `ScalarReference` for
non-object types. You can use it explicitly if you want to wrap an
object scalar property (e.g. JSON value).

```ts
const user = await em.findOne(User, 1);
const passwordHash = await user.passwordHash.load();
```
@B4nan B4nan mentioned this pull request Oct 2, 2023
22 tasks
B4nan added a commit that referenced this pull request Oct 2, 2023
Similarly to the `Reference` wrapper, we can also wrap scalars with
`Ref` into a `ScalarReference` object. This is handy for lazy scalar
properties.

```ts
@Property({ lazy: true, ref: true })
passwordHash!: Ref<string>;
```

The `Ref` type automatically resolves to `ScalarReference` for
non-object types. You can use it explicitly if you want to wrap an
object scalar property (e.g. JSON value).

```ts
const user = await em.findOne(User, 1);
const passwordHash = await user.passwordHash.load();
```
B4nan added a commit that referenced this pull request Oct 17, 2023
Similarly to the `Reference` wrapper, we can also wrap scalars with
`Ref` into a `ScalarReference` object. This is handy for lazy scalar
properties.

```ts
@Property({ lazy: true, ref: true })
passwordHash!: Ref<string>;
```

The `Ref` type automatically resolves to `ScalarReference` for
non-object types. You can use it explicitly if you want to wrap an
object scalar property (e.g. JSON value).

```ts
const user = await em.findOne(User, 1);
const passwordHash = await user.passwordHash.load();
```
B4nan added a commit that referenced this pull request Oct 21, 2023
Similarly to the `Reference` wrapper, we can also wrap scalars with
`Ref` into a `ScalarReference` object. This is handy for lazy scalar
properties.

```ts
@Property({ lazy: true, ref: true })
passwordHash!: Ref<string>;
```

The `Ref` type automatically resolves to `ScalarReference` for
non-object types. You can use it explicitly if you want to wrap an
object scalar property (e.g. JSON value).

```ts
const user = await em.findOne(User, 1);
const passwordHash = await user.passwordHash.load();
```
B4nan added a commit that referenced this pull request Oct 25, 2023
Similarly to the `Reference` wrapper, we can also wrap scalars with
`Ref` into a `ScalarReference` object. This is handy for lazy scalar
properties.

```ts
@Property({ lazy: true, ref: true })
passwordHash!: Ref<string>;
```

The `Ref` type automatically resolves to `ScalarReference` for
non-object types. You can use it explicitly if you want to wrap an
object scalar property (e.g. JSON value).

```ts
const user = await em.findOne(User, 1);
const passwordHash = await user.passwordHash.load();
```
B4nan added a commit that referenced this pull request Nov 2, 2023
Similarly to the `Reference` wrapper, we can also wrap scalars with
`Ref` into a `ScalarReference` object. This is handy for lazy scalar
properties.

```ts
@Property({ lazy: true, ref: true })
passwordHash!: Ref<string>;
```

The `Ref` type automatically resolves to `ScalarReference` for
non-object types. You can use it explicitly if you want to wrap an
object scalar property (e.g. JSON value).

```ts
const user = await em.findOne(User, 1);
const passwordHash = await user.passwordHash.load();
```
B4nan added a commit that referenced this pull request Nov 5, 2023
Similarly to the `Reference` wrapper, we can also wrap scalars with
`Ref` into a `ScalarReference` object. This is handy for lazy scalar
properties.

```ts
@Property({ lazy: true, ref: true })
passwordHash!: Ref<string>;
```

The `Ref` type automatically resolves to `ScalarReference` for
non-object types. You can use it explicitly if you want to wrap an
object scalar property (e.g. JSON value).

```ts
const user = await em.findOne(User, 1);
const passwordHash = await user.passwordHash.load();
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant