@t4h.framework/orm 0.7.4 → 0.8.0
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.
|
@@ -101,11 +101,13 @@ class Account { /* ... */ }
|
|
|
101
101
|
|
|
102
102
|
## ORM configuration
|
|
103
103
|
|
|
104
|
-
`ORM` extends `SerializableClass` — instances can be serialized for workflow persistence.
|
|
104
|
+
`ORM` extends `SerializableClass` — instances can be serialized for workflow persistence. `connectionString` is the `Secret` an `EnvDesign` entry declared `type: Secret` hands the workflow (a string is a `tsc` error); the host reads the value where each query runs.
|
|
105
105
|
|
|
106
106
|
```typescript
|
|
107
|
+
import { environments } from '../constants/environments.js'
|
|
108
|
+
|
|
107
109
|
const orm = new ORM({
|
|
108
|
-
connectionString:
|
|
110
|
+
connectionString: environments.DATABASE_URL, // Secret
|
|
109
111
|
entities: [User, Product],
|
|
110
112
|
})
|
|
111
113
|
```
|
|
@@ -284,7 +286,7 @@ Prefer **`ORM` / `Ref` APIs** in workflow code — they apply constraints and re
|
|
|
284
286
|
Define entities, instantiate `ORM` with `connectionString` + `entities`, and use it inside a `Workflow`:
|
|
285
287
|
|
|
286
288
|
```typescript
|
|
287
|
-
export const orm = new ORM({ connectionString:
|
|
289
|
+
export const orm = new ORM({ connectionString: environments.DATABASE_URL, entities: [User] })
|
|
288
290
|
|
|
289
291
|
export const ormWorkflow = new Workflow({ id: 'orm' }, async () => {
|
|
290
292
|
await orm.create(User, { name: 'John', email: 'john@example.com', age: 20 })
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,52 @@
|
|
|
1
1
|
# @t4h.framework/orm
|
|
2
2
|
|
|
3
|
+
## 0.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#181](https://github.com/tech4humans-brasil/framework/pull/181) [`9449e4e`](https://github.com/tech4humans-brasil/framework/commit/9449e4e9889f42dea1d52418140f47d25dff0535) Thanks [@gusteycamargo](https://github.com/gusteycamargo)! - A credential is a `Secret`, never a string. An env entry declared with
|
|
8
|
+
`type: Secret` hands the workflow the name of the variable; the host binds the
|
|
9
|
+
value where the activity runs, so no input, output or history record holds it.
|
|
10
|
+
|
|
11
|
+
**Breaking**: every field that carries a credential now accepts only a
|
|
12
|
+
`Secret`. Declare the entry with `type: Secret` in your `EnvDesign` and pass it
|
|
13
|
+
whole; `tsc` points at each remaining string.
|
|
14
|
+
|
|
15
|
+
**core**: `Secret` (a `SerializableClass` whose `toString`, `valueOf` and
|
|
16
|
+
`toJSON` throw), `Secret.resolve` and `Secret.read` for hosts, `Secret.FORMAT`
|
|
17
|
+
for the manifest. `EnvDesign` accepts `type: Secret`, refuses a `defaultValue`
|
|
18
|
+
on a secret entry and throws when a `String` entry receives a secret.
|
|
19
|
+
`AsyncActivityCallbackAuth` carries a `Secret` in `secret`, `password`, `token`
|
|
20
|
+
and `value`.
|
|
21
|
+
|
|
22
|
+
**http**: `auth` accepts `{ username, password }`, `{ bearer }` or
|
|
23
|
+
`{ header, value }` besides an `HttpAuth`, all with a `Secret`, and the
|
|
24
|
+
activity writes the header on the host. `clientSecret` and `password` of the
|
|
25
|
+
OAuth2 grants are a `Secret`.
|
|
26
|
+
|
|
27
|
+
**smtp**, **sftp**, **orm**: `connectionString` is a `Secret`. The
|
|
28
|
+
`SftpConnectionString` and `ORMConnectionString` aliases are gone.
|
|
29
|
+
|
|
30
|
+
**hmac**: the callback authorizer reads the secret through `Secret.read`.
|
|
31
|
+
|
|
32
|
+
**dev**: the codec writes a `Secret` by name and binds the env value only where
|
|
33
|
+
an activity runs, reading the input back from the database as the runtime does.
|
|
34
|
+
The SFTP and SMTP claims read the value on connect.
|
|
35
|
+
|
|
36
|
+
**webhook**: documents the `Secret` in `auth`.
|
|
37
|
+
|
|
38
|
+
### Patch Changes
|
|
39
|
+
|
|
40
|
+
- Updated dependencies [[`9449e4e`](https://github.com/tech4humans-brasil/framework/commit/9449e4e9889f42dea1d52418140f47d25dff0535), [`9449e4e`](https://github.com/tech4humans-brasil/framework/commit/9449e4e9889f42dea1d52418140f47d25dff0535)]:
|
|
41
|
+
- @t4h.framework/core@0.15.0
|
|
42
|
+
|
|
43
|
+
## 0.7.5
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- Updated dependencies [[`aa72268`](https://github.com/tech4humans-brasil/framework/commit/aa72268d040a743743cac31cc14e26b8620b0e3f)]:
|
|
48
|
+
- @t4h.framework/core@0.14.0
|
|
49
|
+
|
|
3
50
|
## 0.7.4
|
|
4
51
|
|
|
5
52
|
### Patch Changes
|
package/dist/models/ORM.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { SerializableClass, type PromiseLikeType } from '@t4h.framework/core';
|
|
1
|
+
import { SerializableClass, type Deserializer, type PromiseLikeType, type Secret, type Serializer } from '@t4h.framework/core';
|
|
2
2
|
import { Ref } from './Ref.js';
|
|
3
3
|
import { RefCollection } from './RefCollection.js';
|
|
4
4
|
import { type EntityMetadata } from '../decorators/metadata.js';
|
|
5
5
|
import type { FindWhere } from '../typings/FindWhere.js';
|
|
6
6
|
import type { EntityConstructor, EntityData, EntityInsertData } from '../typings/ORM.js';
|
|
7
7
|
export interface ORMConfig {
|
|
8
|
-
connectionString:
|
|
8
|
+
connectionString: Secret;
|
|
9
9
|
entities: EntityMetadata[];
|
|
10
10
|
}
|
|
11
11
|
export interface FindOneOptions<T> {
|
|
@@ -20,8 +20,8 @@ export interface FindOptions<T> extends FindOneOptions<T> {
|
|
|
20
20
|
}
|
|
21
21
|
export declare class ORM extends SerializableClass {
|
|
22
22
|
readonly config: ORMConfig;
|
|
23
|
-
toSerializable(): {
|
|
24
|
-
connectionString:
|
|
23
|
+
toSerializable(serializer: Serializer): Promise<{
|
|
24
|
+
connectionString: import("@t4h.framework/core").Serializable;
|
|
25
25
|
entities: {
|
|
26
26
|
tableName: string | undefined;
|
|
27
27
|
indexes: {
|
|
@@ -36,10 +36,10 @@ export declare class ORM extends SerializableClass {
|
|
|
36
36
|
index: boolean | undefined;
|
|
37
37
|
}[];
|
|
38
38
|
}[];
|
|
39
|
-
}
|
|
40
|
-
protected fromSerializable(serializable: PromiseLikeType<ReturnType<this['toSerializable']
|
|
39
|
+
}>;
|
|
40
|
+
protected fromSerializable(serializable: PromiseLikeType<ReturnType<this['toSerializable']>>, deserializer: Deserializer): Promise<void>;
|
|
41
41
|
constructor(config: {
|
|
42
|
-
connectionString:
|
|
42
|
+
connectionString: Secret;
|
|
43
43
|
entities: EntityConstructor[];
|
|
44
44
|
});
|
|
45
45
|
create<T>(entity: EntityConstructor<T>, data: EntityInsertData<T>): Promise<Ref<T>>;
|
package/dist/models/ORM.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ORM.d.ts","sourceRoot":"","sources":["../../src/models/ORM.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EACjB,KAAK,eAAe,
|
|
1
|
+
{"version":3,"file":"ORM.d.ts","sourceRoot":"","sources":["../../src/models/ORM.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,iBAAiB,EACjB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,MAAM,EACX,KAAK,UAAU,EAChB,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAMlD,OAAO,EAGL,KAAK,cAAc,EACpB,MAAM,2BAA2B,CAAA;AAClC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EACV,iBAAiB,EACjB,UAAU,EACV,gBAAgB,EAGjB,MAAM,mBAAmB,CAAA;AAM1B,MAAM,WAAW,SAAS;IACxB,gBAAgB,EAAE,MAAM,CAAA;IACxB,QAAQ,EAAE,cAAc,EAAE,CAAA;CAC3B;AAED,MAAM,WAAW,cAAc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,IAAI,CAAC,CAAC,EACjB,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC5B,OAAO,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,GACvB,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAaf,MAAM,CAAC,CAAC,EACnB,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC5B,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,GACzB,OAAO,CAAC,OAAO,CAAC;CAGpB"}
|
package/dist/models/ORM.js
CHANGED
|
@@ -12,9 +12,9 @@ const find = History.bind(ORMFindActivity);
|
|
|
12
12
|
const findOne = History.bind(ORMFindOneActivity);
|
|
13
13
|
export class ORM extends SerializableClass {
|
|
14
14
|
config;
|
|
15
|
-
toSerializable() {
|
|
15
|
+
async toSerializable(serializer) {
|
|
16
16
|
return {
|
|
17
|
-
connectionString: this.config.connectionString,
|
|
17
|
+
connectionString: await serializer(this.config.connectionString),
|
|
18
18
|
entities: this.config.entities.map(entity => ({
|
|
19
19
|
tableName: entity.tableName,
|
|
20
20
|
indexes: entity.indexes.map(index => ({
|
|
@@ -31,10 +31,10 @@ export class ORM extends SerializableClass {
|
|
|
31
31
|
})),
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
-
fromSerializable(serializable) {
|
|
34
|
+
async fromSerializable(serializable, deserializer) {
|
|
35
35
|
Object.assign(this, {
|
|
36
36
|
config: {
|
|
37
|
-
connectionString: serializable.connectionString,
|
|
37
|
+
connectionString: (await deserializer(serializable.connectionString)),
|
|
38
38
|
entities: serializable.entities.map(entity => ({
|
|
39
39
|
tableName: entity.tableName,
|
|
40
40
|
indexes: entity.indexes,
|
package/dist/models/ORM.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ORM.js","sourceRoot":"","sources":["../../src/models/ORM.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EACP,iBAAiB,
|
|
1
|
+
{"version":3,"file":"ORM.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;YACtB,GAAG,EAAE,IAAI;YACT,KAAK,EAAE,kBAAkB,CAAC,MAAM,CAAC;YACjC,KAAK,EAAE,CAAC,OAAO,EAAE,KAAK,IAAI,EAAE,CAAsB;YAClD,OAAO,EAAE,OAAO,EAAE,OAAqD;YACvE,KAAK,EAAE,OAAO,EAAE,KAAK;YACrB,MAAM,EAAE,OAAO,EAAE,MAAM;SACxB,CAAC,CAAA;QAEF,OAAO,IAAI,aAAa,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.
|
|
3
|
+
"version": "0.8.0",
|
|
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.
|
|
38
|
+
"@t4h.framework/core": "^0.15.0",
|
|
39
39
|
"typescript": "^5.9.3",
|
|
40
40
|
"vitest": "^4.0.18"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@t4h.framework/core": "^0.
|
|
43
|
+
"@t4h.framework/core": "^0.15.0"
|
|
44
44
|
},
|
|
45
45
|
"packageManager": "yarn@4.12.0",
|
|
46
46
|
"engines": {
|