nest-my-admin 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.
Files changed (2) hide show
  1. package/README.md +37 -0
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -615,6 +615,39 @@ export class ShopSettingsPage implements AdminSettingsSource<ShopSettingsDto> {
615
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' })`.
616
616
  - **API.** `GET /api/pages/:name` answers `{ schema, values, secrets, files }`, and `PATCH /api/pages/:name` takes the changed keys and answers the same.
617
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
+
618
651
  ### Inlines
619
652
 
620
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:
@@ -936,6 +969,10 @@ Things hosts tend to write by hand that the admin already does:
936
969
  - **Inline children stay out of the sidebar** by default (`nav: false` unless they set `nav`): no extra group to hide them in.
937
970
  - **Labels in one language** are plain strings; other languages can come from `translate` (see Languages, theme and branding).
938
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
+
939
976
  ## Upgrading to 0.7.4
940
977
 
941
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).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nest-my-admin",
3
- "version": "0.7.4",
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.7.4",
43
- "@nest-my-admin/core": "0.7.4",
44
- "@nest-my-admin/testing": "0.7.4"
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
  }