nest-my-admin 0.7.3 → 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.
- package/README.md +44 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -328,7 +328,7 @@ export class ProductAdmin extends AdminResourceBase<Product> {
|
|
|
328
328
|
- A widget that does not fit the type (`money` on a boolean) fails at boot.
|
|
329
329
|
- `colors` for badges: gray, red, amber, green, blue, purple or pink.
|
|
330
330
|
- `currency` for money: display only. Money is grouped as you leave the input, and the commas are dropped when saving.
|
|
331
|
-
- **Validation at boot.** Unknown fields, widgets and colours fail at boot with a did-you-mean hint, and so do `showIf`/`slugFrom` names and enum labels for values the column does not have.
|
|
331
|
+
- **Validation at boot.** Unknown fields, widgets and colours fail at boot with a did-you-mean hint, and so do `showIf`/`slugFrom`/`fillFrom` names, defaults that do not fit their field and enum labels for values the column does not have.
|
|
332
332
|
- **Read-only fields.**
|
|
333
333
|
- `readonly: true` shows the field on edit forms as text with a lock and removes it from `form.update`.
|
|
334
334
|
- `readonlyIf(record)` runs on the server for every record. Records carry `_readonly` (the fields it locks), and a PATCH that sends a locked field is a 422 `{ field: ['is read-only'] }` before your `update` runs. That covers inline cell edits too.
|
|
@@ -343,6 +343,8 @@ export class ProductAdmin extends AdminResourceBase<Product> {
|
|
|
343
343
|
- Create ignores it.
|
|
344
344
|
- **`showIf`** hides a field while other fields do not hold the given value (or one of the values), evaluated live in the browser. A hidden field is not sent and not checked. It is presentation, not a permission: the server keeps the stored value.
|
|
345
345
|
- **`slugFrom`** makes the slug widget fill itself from another field. It keeps the letters of every script and stops once someone types in it, or when it already holds a value.
|
|
346
|
+
- **`default`** is the value a new form starts with: an action's input form, or a resource's create form (a duplicate starts from the copied record). It must fit the field (a string for text, enum, date and datetime fields, a number, or `true`/`false`); the DTO still validates whatever is sent.
|
|
347
|
+
- **`fillFrom`** makes a text field fill itself from other fields of the same form, as the user types: `domain: { fillFrom: '{crm}.example.com' }`, `apiDomain: { fillFrom: 'api.{domain}' }` (chains are fine, circles fail at boot). The value is empty while a field it names is empty. It stops following once someone types in it and follows again when they clear it; a field that already holds a value (a stored record) starts as typed. It works in action dialogs too, where `slugFrom` does not.
|
|
346
348
|
- **Layout.**
|
|
347
349
|
- `form.layout` has sections (a title, and 1–3 columns on wide screens, one on phones) and tabs.
|
|
348
350
|
- Every name must be on a form and listed once. Fields left out go into a last section.
|
|
@@ -613,6 +615,39 @@ export class ShopSettingsPage implements AdminSettingsSource<ShopSettingsDto> {
|
|
|
613
615
|
- **Names.** Letters, digits, `-` and `_`; not the name of a resource, an operation (`view`, `update`, …) or a resource's custom permission. Because page codes start with `page.`, **a resource cannot be named `page` in an admin with settings pages**: boot fails and suggests `@AdminResource(Page, { name: 'content-page' })`.
|
|
614
616
|
- **API.** `GET /api/pages/:name` answers `{ schema, values, secrets, files }`, and `PATCH /api/pages/:name` takes the changed keys and answers the same.
|
|
615
617
|
|
|
618
|
+
### Source resources
|
|
619
|
+
|
|
620
|
+
Rows that are not database rows (DNS records behind an HTTP API, files on disk, live container status) get the same list, record page, forms and actions as a table: `@AdminSource(RowClass, options)` on a class that extends `AdminSourceBase`. The demo's couriers (`examples/demo-api/src/sales/courier.source.ts`) are one.
|
|
621
|
+
|
|
622
|
+
```ts
|
|
623
|
+
export class DnsRow {
|
|
624
|
+
@IsString() id: string;
|
|
625
|
+
@IsString() name: string;
|
|
626
|
+
@IsIn(['a', 'cname', 'txt']) type: string;
|
|
627
|
+
@IsString() value: string;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
@AdminSource(DnsRow, { name: 'dns', label: 'DNS records', title: 'name' }) // primaryKey: 'id' by default
|
|
631
|
+
export class DnsAdmin extends AdminSourceBase<DnsRow, string> {
|
|
632
|
+
list: ListConfig<DnsRow> = { columns: ['name', 'type', 'value'], search: ['name', 'value'], filters: ['type'], sort: 'name' };
|
|
633
|
+
form = { create: CreateDnsDto, update: UpdateDnsDto };
|
|
634
|
+
|
|
635
|
+
constructor(private readonly dns: DnsClient) { super(); }
|
|
636
|
+
|
|
637
|
+
async findMany(params: ListParams) { return inMemoryList(await this.dns.all(), params); }
|
|
638
|
+
async findOne(id: string) { return (await this.dns.all()).find((row) => row.id === id) ?? null; }
|
|
639
|
+
override async create(dto: object) { return this.dns.create(dto as CreateDnsDto); }
|
|
640
|
+
override async update(id: string, dto: object) { return this.dns.update(id, dto as UpdateDnsDto); }
|
|
641
|
+
override async delete(id: string) { await this.dns.delete(id); }
|
|
642
|
+
}
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
- **The row class** is the schema: one field per property with a class-validator decorator, typed like a DTO's (`@IsIn` is an enum, `@IsInt` an integer, `@IsDate` a date). `@AdminField` and `fields` set labels, help and widgets. `primaryKey` names the id property (or several); it defaults to `id`.
|
|
646
|
+
- **`findMany(params, ctx)`** answers a page: `{ items, total }`. `params` carries the search (`term` and the `list.search` fields), the filters, the sort and the page. `inMemoryList(rows, params)` does all of it for rows fetched whole; an API that searches and pages itself can be asked directly. **`findOne(id, ctx)`** answers one row, or `null` (a 404).
|
|
647
|
+
- **Writes are opt-in.** Override `create`, `update` and `delete` to allow them. A source that does not is offered no New, Save or Delete, and the API refuses them with 403 whatever the roles say. Throw `AdminFieldError` to refuse a value (422 on the field), as anywhere.
|
|
648
|
+
- **No DataSource.** `ctx.manager` is never set and writes run without a transaction: a source writes to its own system, which the admin cannot roll back. Actions (record, bulk and resource actions), permissions, global search and the command palette work as on a table. Row scopes do not apply, and writes to a source are not in the audit log. `@BeforeSave`, `@AfterSave` and `@BeforeDelete` run only if your `create`, `update` and `delete` call `this.runHooks(...)`, as for any override.
|
|
649
|
+
- **Refused at boot**, with a sentence: list tabs, computed columns, keyset paging, a `count` other than exact, export, inlines, relation cards, form history, file/image/rich-text widgets and atomic actions. They need a database.
|
|
650
|
+
|
|
616
651
|
### Inlines
|
|
617
652
|
|
|
618
653
|
A parent's form can edit its child records (a product's variants, specifications and pictures; an order's lines), and one Save writes the parent and every change to its children in **one transaction**. The child is an ordinary resource, with its own permissions, scopes, fields, DTOs, hooks and service overrides; the parent's layout places it:
|
|
@@ -934,6 +969,14 @@ Things hosts tend to write by hand that the admin already does:
|
|
|
934
969
|
- **Inline children stay out of the sidebar** by default (`nav: false` unless they set `nav`): no extra group to hide them in.
|
|
935
970
|
- **Labels in one language** are plain strings; other languages can come from `translate` (see Languages, theme and branding).
|
|
936
971
|
|
|
972
|
+
## Upgrading to 0.8.0
|
|
973
|
+
|
|
974
|
+
Nothing to change. New: [source resources](#source-resources): `@AdminSource(RowClass, …)` and `AdminSourceBase` give rows that are not database rows (an HTTP API, files, live state) the list, record page, forms and actions of a table; `inMemoryList` searches, filters, sorts and pages rows fetched whole.
|
|
975
|
+
|
|
976
|
+
## Upgrading to 0.7.4
|
|
977
|
+
|
|
978
|
+
Nothing to change. New: `@AdminField({ default })` starts action input forms and create forms at a value (checked at boot to fit the field), and `@AdminField({ fillFrom: '{crm}.example.com' })` fills a text field from other fields of the same form until someone types in it, in action dialogs too (see Field config).
|
|
979
|
+
|
|
937
980
|
## Upgrading to 0.7.3
|
|
938
981
|
|
|
939
982
|
Nothing to change. Smaller packages: `@nest-my-admin/core`, `/auth` and `/testing` no longer ship source maps (they pointed at sources the packages do not include), so core is about 1.2 MB instead of 1.9 MB; core no longer asks for `rxjs` and `@nest-my-admin/testing` no longer asks for `@nestjs/core`, neither of which they import.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nest-my-admin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Django-admin-class admin panel for NestJS + TypeORM: @nest-my-admin/core, /auth and /testing under one name",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@nest-my-admin/auth": "0.
|
|
43
|
-
"@nest-my-admin/core": "0.
|
|
44
|
-
"@nest-my-admin/testing": "0.
|
|
42
|
+
"@nest-my-admin/auth": "0.8.0",
|
|
43
|
+
"@nest-my-admin/core": "0.8.0",
|
|
44
|
+
"@nest-my-admin/testing": "0.8.0"
|
|
45
45
|
}
|
|
46
46
|
}
|