@t4h.framework/orm 0.7.0 → 0.7.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # @t4h.framework/orm
2
2
 
3
+ ## 0.7.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#164](https://github.com/tech4humans-brasil/framework/pull/164) [`711344b`](https://github.com/tech4humans-brasil/framework/commit/711344b6218c3d750f3595b6037c0ac2df127e4c) Thanks [@gusteycamargo](https://github.com/gusteycamargo)! - Fix `orm.find(Entity)` returning no rows when called without a `where`.
8
+
9
+ `SerializableFindInput.where` is declared required, but `ORM.find` passed
10
+ `options?.where as SerializableWhere` — a cast that handed `undefined` to every
11
+ claim implementation. The dev server feeds that straight to sift, and
12
+ `sift(undefined)` matches nothing, so a find with no filter came back empty
13
+ instead of returning every row. `ORM.find` now sends an empty query.
14
+
15
+ `DevORMClaim` also read `limit: 0` as no limit and returned every row, where SQL
16
+ `LIMIT 0` returns none.
17
+
18
+ The ORM README documented a `unique` property option and an
19
+ `assertUniqueConstraint` pipeline step that do not exist — `@Property({ unique:
20
+ true })` is a type error, and `assert-constraints` only checks types and
21
+ non-nullable properties. The entity examples also did not compile: `id` and any
22
+ property with a `default` have to be optional and `nullable`, since
23
+ `EntityInsertData` requires every declared key and a missing non-nullable
24
+ property fails validation.
25
+
26
+ ## 0.7.1
27
+
28
+ ### Patch Changes
29
+
30
+ - Updated dependencies [[`8e8ffb2`](https://github.com/tech4humans-brasil/framework/commit/8e8ffb2ac0739e2f2a1f0af2ed9ebeffe2964776)]:
31
+ - @t4h.framework/core@0.11.0
32
+
3
33
  ## 0.7.0
4
34
 
5
35
  ### Minor Changes
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Tech for humans
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 CHANGED
@@ -33,20 +33,25 @@ import { Entity, Property } from '@t4h.framework/orm'
33
33
 
34
34
  @Entity({ tableName: 'users' })
35
35
  class User {
36
- @Property({ type: 'uuid' })
37
- public id!: string
36
+ @Property({ type: 'uuid', nullable: true })
37
+ public id?: string
38
38
 
39
39
  @Property({ type: 'string' })
40
40
  public name!: string
41
41
 
42
- @Property({ type: 'string', unique: true })
42
+ @Property({ type: 'string' })
43
43
  public email!: string
44
44
 
45
45
  @Property({ type: 'boolean', default: true })
46
- public active!: boolean
46
+ public active?: boolean
47
47
  }
48
48
  ```
49
49
 
50
+ `id` is assigned by the store on create, so declare it optional and `nullable`
51
+ — a non-nullable property missing from the data fails
52
+ `assertNonNullablePropertyConstraint`, and `EntityInsertData` would require you
53
+ to pass it yourself. The same goes for any property carrying a `default`.
54
+
50
55
  ### @Entity options
51
56
 
52
57
  ```typescript
@@ -59,8 +64,8 @@ class User {
59
64
  @Property({
60
65
  type?: string,
61
66
  nullable?: boolean,
62
- unique?: boolean,
63
67
  default?: any,
68
+ index?: boolean,
64
69
  })
65
70
  ```
66
71
 
@@ -92,13 +97,11 @@ Row validation runs in the ORM library (`ORM.create` and `Ref.update`), not in `
92
97
  1. `applyDefaultProperties` — fills `default` for `undefined` fields
93
98
  2. `assertPropertyTypeConstraint` — validates declared types
94
99
  3. `assertNonNullablePropertyConstraint` — required fields must be present
95
- 4. `assertUniqueConstraint` — no duplicates in the batch, then no conflicting row in storage via `orm.exists`
96
100
 
97
101
  **Update** (partial patch only):
98
102
 
99
103
  1. Defaults only for keys present in the patch
100
104
  2. Same asserts, scoped to patch keys
101
- 3. Unique checks skip values unchanged vs `getSnapshot()` (same row keeps its current unique value)
102
105
 
103
106
  ### Supported property types
104
107
 
@@ -82,7 +82,7 @@ export class ORM extends SerializableClass {
82
82
  const refs = await find({
83
83
  orm: this,
84
84
  table: getEntityTableName(entity),
85
- where: options?.where,
85
+ where: (options?.where ?? {}),
86
86
  orderBy: options?.orderBy,
87
87
  limit: options?.limit,
88
88
  offset: options?.offset,
@@ -1 +1 @@
1
- {"version":3,"file":"ORM.js","sourceRoot":"","sources":["../../src/models/ORM.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,iBAAiB,GAElB,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAA;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAA;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAA;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAA;AACnF,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAA;AACxE,OAAO,EACL,iBAAiB,EACjB,kBAAkB,GAEnB,MAAM,2BAA2B,CAAA;AAUlC,MAAM,MAAM,GAA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Aa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,CAAA;IAC9C,CAAC;IAEM,KAAK,CAAC,MAAM,CACjB,MAA4B,EAC5B,OAA0B;QAE1B,OAAO,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,KAAK,IAAI,CAAA;IACvD,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t4h.framework/orm",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "ORM module for the T4H Framework",
5
5
  "homepage": "https://github.com/tech4humans-brasil/framework/tree/main/packages/orm",
6
6
  "bugs": "https://github.com/tech4humans-brasil/framework/issues",
@@ -35,12 +35,12 @@
35
35
  "reflect-metadata": "^0.2.2"
36
36
  },
37
37
  "devDependencies": {
38
- "@t4h.framework/core": "^0.10.0",
38
+ "@t4h.framework/core": "^0.11.0",
39
39
  "typescript": "^5.9.3",
40
40
  "vitest": "^4.0.18"
41
41
  },
42
42
  "peerDependencies": {
43
- "@t4h.framework/core": "^0.10.0"
43
+ "@t4h.framework/core": "^0.11.0"
44
44
  },
45
45
  "packageManager": "yarn@4.12.0",
46
46
  "engines": {