Skip to content

Commit

Permalink
Merge pull request #113 from dxfrontier/refactoring
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
dragolea authored Nov 13, 2024
2 parents 6113c93 + d8ebc60 commit bd0f1a2
Show file tree
Hide file tree
Showing 16 changed files with 514 additions and 240 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ jobs:
run: npm run build

- name: Verify @decorator folder, index.ts file, and content
run: ts-node ./postinstall/util/Verifier.ts
run: ts-node ./test/postinstall/Verifier.ts
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ out
# Ignore everything in dist
/dist/*

# But not the postinstall folder
!/dist/postinstall/

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
Expand Down Expand Up @@ -139,6 +136,3 @@ out
.npmrc
@cds-models
@dispatcher

# But not the @dispatcher folder from the test
!/test/bookshop/@dispatcher
27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1326,15 +1326,19 @@ class BookHandler {

**@IsColumnSupplied\<T\>(field : keyof T)**

The `@IsColumnSupplied<T>()` decorator is utilized at the `parameter level`. It allows your to verify the existence of a column in the `SELECT`, `INSERT` or `UPSERT` Query.
The `@IsColumnSupplied<T>(field : keyof T)` decorator is utilized at the `parameter level`. It allows your to verify the existence of a column in the `SELECT`, `INSERT` or `UPSERT` Query.

`Parameters`

- `column (string)`: A string representing the name of the column to be verified.
- `field (string)`: A string representing the name of the column to be verified.

`Type Parameters`

- `T`: The entity type (e.g., `MyEntity`) representing the table or collection on which the decorator operates. This allows TypeScript to enforce type safety for the field parameter.

`Return` :

- `boolean`: This decorator returns `true` if `column` was found, `false` otherwise
- `boolean`: This decorator returns `true` if `field / column` was found, `false` otherwise

`Example`

Expand Down Expand Up @@ -1686,7 +1690,7 @@ public async beforeCreate(

##### @Env

**@Env**
**@Env\<T\>(env: PropertyStringPath\<T\>)**

The `@Env` decorator is a parameter decorator used to inject values from the cds.env configuration object directly into a method parameter.

Expand All @@ -1695,6 +1699,9 @@ The `@Env` decorator is a parameter decorator used to inject values from the cds
- `env (string)`: A string path representing a property from `cds.env`. This path follows the format `property string path`, which allows access to deeply nested configuration properties.
- E.g. : `'requires.db.credentials.url'` corresponds to **cds.env.requires.db.credentials.url** object.

`Type Parameters`

- `T`: The `CDS environmental variables` type (e.g., `cds env get`) representing the collection on which the decorator operates. This allows TypeScript to enforce type safety.

`Return` :

Expand All @@ -1703,8 +1710,7 @@ The `@Env` decorator is a parameter decorator used to inject values from the cds
`Example`

```ts
// Generated import inside of your package.json when you run 'npm install' or install the cds-ts-dispatcher
import { CDS_ENV } from '@dispatcher';
import { CDS_ENV } from '#dispatcher';

@BeforeCreate()
public async beforeCreate(
Expand All @@ -1715,10 +1721,11 @@ public async beforeCreate(
// or any other type if you do not want to use the CDS_ENV generated types
) {
if (dbUrl) {
// handle logic using dbUrl
// handle custom logic ...
}
}
```

> [!NOTE]
> When you install cds-ts-dispatcher `(e.g. npm install @dxfrontier/cds-ts-dispatcher)` or run a general `npm install`, the following will be generated or updated :
> - New `@dispatcher` folder is generated at the project ***root***.
Expand Down Expand Up @@ -1750,6 +1757,12 @@ public async beforeCreate(
> [!NOTE]
> The `@dispatcher` folder is ***regenerated each time you run npm install.***

> [!TIP]
> You can import the generated `CDS env` from the generated `@dispatcher` folder by using :
> ```ts
> import { CDS_ENV } from '#dispatcher';
> ```

<p align="right">(<a href="#table-of-contents">back to top</a>)</p>

#### `Method`-`active entity`
Expand Down
159 changes: 0 additions & 159 deletions dist/postinstall/PostInstall.js

This file was deleted.

2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export default tseslint.config(
},
},
{
ignores: ['@dispatcher/', 'dist/', 'build/', 'test/', 'lib/docs/', '*.js'],
ignores: ['@dispatcher/', 'dist/', 'build/', 'test/', 'lib/docs/', '*.js', 'postinstall/'],
},
);
Loading

0 comments on commit bd0f1a2

Please sign in to comment.