@nest-my-admin/core 0.8.1 → 0.9.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 +23 -2
- package/dist/api/action.service.js +24 -6
- package/dist/api/admin-api.service.js +38 -16
- package/dist/audit/audit-reader.js +3 -2
- package/dist/auth/auth.service.js +9 -1
- package/dist/crud/computed-columns.js +9 -0
- package/dist/dashboard/dashboard.service.js +2 -1
- package/dist/dashboard/widget-data.d.ts +8 -0
- package/dist/dashboard/widget-data.js +55 -0
- package/dist/decorators/admin-action.d.ts +29 -5
- package/dist/decorators/admin-action.js +50 -14
- package/dist/decorators/admin-print.d.ts +4 -1
- package/dist/decorators/admin-print.js +0 -6
- package/dist/decorators/admin-resource.d.ts +6 -2
- package/dist/decorators/admin-scope.d.ts +5 -2
- package/dist/decorators/admin-scope.js +0 -6
- package/dist/decorators/admin-settings-page.d.ts +2 -1
- package/dist/decorators/admin-widget.d.ts +2 -1
- package/dist/decorators/hooks.d.ts +11 -6
- package/dist/decorators/hooks.js +3 -3
- package/dist/decorators/typed.d.ts +20 -0
- package/dist/decorators/typed.js +2 -0
- package/dist/files/file-owner.js +2 -1
- package/dist/host-contract.d.ts +30 -0
- package/dist/host-contract.js +91 -0
- package/dist/http/error-response.js +4 -0
- package/dist/i18n/texts.js +9 -3
- package/dist/index.d.ts +2 -1
- package/dist/inlines/inline-reader.js +3 -2
- package/dist/inlines/inline-writer.js +3 -2
- package/dist/options.js +23 -1
- package/dist/pages/page-registry.js +3 -2
- package/dist/policy/admin-policy.service.js +30 -11
- package/dist/policy/explain.js +3 -2
- package/dist/rbac/rbac-routes.js +2 -1
- package/dist/registry/resource-registry.js +1 -1
- package/dist/resource/admin-resource-base.js +16 -5
- package/dist/resource/admin-source-base.d.ts +2 -0
- package/package.json +2 -2
|
@@ -2,6 +2,9 @@ import 'reflect-metadata';
|
|
|
2
2
|
import type { PrintSchema } from '../contract.js';
|
|
3
3
|
import { type LocalizedText } from '../i18n/localized-text.js';
|
|
4
4
|
import type { ScopedText } from '../i18n/texts.js';
|
|
5
|
+
import type { HtmlString } from '../print/html.js';
|
|
6
|
+
import type { AdminContext } from '../resource/admin-context.js';
|
|
7
|
+
import type { Awaitable, RowOf } from './typed.js';
|
|
5
8
|
/** Paper sizes by name; any other string is used as the CSS `@page { size }` value. */
|
|
6
9
|
export declare const PAPERS: Record<string, string>;
|
|
7
10
|
export interface AdminPrintOptions {
|
|
@@ -28,7 +31,7 @@ export interface RegisteredPrint {
|
|
|
28
31
|
* wraps it in a page sized for `paper` that prints itself. Printing needs `{resource}.view`, the user's row scopes and
|
|
29
32
|
* `{resource}.print.{name}`; each printed record is written to the audit log. Throw an `HttpException` to refuse.
|
|
30
33
|
*/
|
|
31
|
-
export declare function AdminPrint(options?: AdminPrintOptions):
|
|
34
|
+
export declare function AdminPrint(options?: AdminPrintOptions): <P extends object, T extends (records: Array<RowOf<P>>, ctx: AdminContext) => Awaitable<HtmlString>>(target: P, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => void;
|
|
32
35
|
/** Boot checks of a resource class's print templates; `taken` are names already in use (base methods, actions). */
|
|
33
36
|
export declare function resolvePrints(resourceClass: Function, taken: readonly string[], fail: (message: string) => never): Map<string, RegisteredPrint>;
|
|
34
37
|
/** The permission code of a print template. */
|
|
@@ -3,12 +3,6 @@ import { ADMIN_PRINTS_METADATA } from '../constants.js';
|
|
|
3
3
|
import { humanize } from '../schema/humanize.js';
|
|
4
4
|
/** Paper sizes by name; any other string is used as the CSS `@page { size }` value. */
|
|
5
5
|
export const PAPERS = { A4: 'A4', A5: 'A5', label: '100mm 150mm' };
|
|
6
|
-
/**
|
|
7
|
-
* A print template of a resource (an invoice, a shipping label): the method `(records, ctx)` returns the body HTML of
|
|
8
|
-
* the printed page, one or more records (`bulk`). Build it with the `html` tag, which escapes every value. The admin
|
|
9
|
-
* wraps it in a page sized for `paper` that prints itself. Printing needs `{resource}.view`, the user's row scopes and
|
|
10
|
-
* `{resource}.print.{name}`; each printed record is written to the audit log. Throw an `HttpException` to refuse.
|
|
11
|
-
*/
|
|
12
6
|
export function AdminPrint(options = {}) {
|
|
13
7
|
return (target, propertyKey) => {
|
|
14
8
|
if (typeof propertyKey !== 'string')
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
+
import type { ObjectLiteral } from 'typeorm';
|
|
3
|
+
import type { AdminResourceBase } from '../resource/admin-resource-base.js';
|
|
4
|
+
import type { AdminSourceBase } from '../resource/admin-source-base.js';
|
|
5
|
+
import type { TypedClassDecorator } from './typed.js';
|
|
2
6
|
import type { LocalizedText } from '../i18n/localized-text.js';
|
|
3
7
|
import type { TitleDefinition } from '../schema/titles.js';
|
|
4
8
|
export interface AdminResourceOptions {
|
|
@@ -55,7 +59,7 @@ export interface AdminSourceOptions extends Omit<AdminResourceOptions, 'dataSour
|
|
|
55
59
|
* extends AdminSourceBase and answers `findMany`/`findOne` (and `create`/`update`/`delete` when it allows them).
|
|
56
60
|
* `row` is a class whose class-validator decorators describe a row's fields, like an action's input DTO.
|
|
57
61
|
*/
|
|
58
|
-
export declare function AdminSource(row:
|
|
62
|
+
export declare function AdminSource<R extends ObjectLiteral>(row: abstract new (...args: any[]) => R, options?: AdminSourceOptions): TypedClassDecorator<AdminSourceBase<R, any>>;
|
|
59
63
|
/** Marks a provider as an admin resource for `entity`. The class must extend AdminResourceBase. */
|
|
60
|
-
export declare function AdminResource(entity:
|
|
64
|
+
export declare function AdminResource<E extends ObjectLiteral>(entity: abstract new (...args: any[]) => E, options?: AdminResourceOptions): TypedClassDecorator<AdminResourceBase<E, any>>;
|
|
61
65
|
export declare function getAdminResourceDefinition(target: Function): AdminResourceDefinition | undefined;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
2
|
import type { WhereExpressionBuilder } from 'typeorm';
|
|
3
|
+
import type { AdminContext } from '../resource/admin-context.js';
|
|
4
|
+
import type { RecordMethodDecorator, TypedMethodDecorator } from './typed.js';
|
|
3
5
|
/**
|
|
4
6
|
* What a scope returns: a column map (`{ ownerId: ctx.user.id }`; an array means IN, null means IS NULL), or a
|
|
5
7
|
* callback that adds conditions for anything else (`(where, alias) => where.where(`${alias}.total > 0`)`).
|
|
@@ -9,7 +11,7 @@ export type ScopeCondition = Record<string, unknown> | ((where: WhereExpressionB
|
|
|
9
11
|
* A named row scope (spec §6.4): `@AdminScope('own') own(ctx) { return { ownerId: ctx.user.id }; }`. Roles assign
|
|
10
12
|
* scopes per resource and operation; the method runs per request and must not throw for a normal user.
|
|
11
13
|
*/
|
|
12
|
-
export declare function AdminScope(name: string):
|
|
14
|
+
export declare function AdminScope(name: string): TypedMethodDecorator<(ctx: AdminContext) => ScopeCondition>;
|
|
13
15
|
export declare function getScopes(target: Function): Record<string, string | symbol>;
|
|
14
16
|
export type RecordOperation = 'update' | 'delete';
|
|
15
17
|
/**
|
|
@@ -18,7 +20,8 @@ export type RecordOperation = 'update' | 'delete';
|
|
|
18
20
|
* (`@AdminCan('ship')`) rules that action the same way: `_perm.actions` lists it only where the rule agrees, and
|
|
19
21
|
* running it elsewhere is a 403. Any other name fails at boot.
|
|
20
22
|
*/
|
|
21
|
-
export declare function AdminCan(operation:
|
|
23
|
+
export declare function AdminCan(operation: 'create'): TypedMethodDecorator<(parent: any, ctx: AdminContext) => boolean>;
|
|
24
|
+
export declare function AdminCan(operation: RecordOperation | (string & {})): RecordMethodDecorator<[ctx: AdminContext], boolean>;
|
|
22
25
|
/** The rule methods for an operation (`update`, `delete`) or a record action's name. */
|
|
23
26
|
export declare function getCanRules(target: Function, operation: string): Array<string | symbol>;
|
|
24
27
|
/** Every name the class has `@AdminCan` rules for. */
|
|
@@ -14,12 +14,6 @@ export function AdminScope(name) {
|
|
|
14
14
|
export function getScopes(target) {
|
|
15
15
|
return Reflect.getMetadata(ADMIN_SCOPES_METADATA, target) ?? {};
|
|
16
16
|
}
|
|
17
|
-
/**
|
|
18
|
-
* A per-record rule (spec §6.3): `@AdminCan('update') canEdit(record, ctx) { return record.status === 'draft'; }`.
|
|
19
|
-
* Records carry the answer in `_perm`; PATCH and DELETE re-check it (403). The name of a record `@AdminAction`
|
|
20
|
-
* (`@AdminCan('ship')`) rules that action the same way: `_perm.actions` lists it only where the rule agrees, and
|
|
21
|
-
* running it elsewhere is a 403. Any other name fails at boot.
|
|
22
|
-
*/
|
|
23
17
|
export function AdminCan(operation) {
|
|
24
18
|
return (target, propertyKey) => {
|
|
25
19
|
const owner = target.constructor;
|
|
@@ -3,6 +3,7 @@ import type { LocalizedText } from '../i18n/localized-text.js';
|
|
|
3
3
|
import type { AdminContext } from '../resource/admin-context.js';
|
|
4
4
|
import type { LayoutConfig } from '../schema/field-config.js';
|
|
5
5
|
import type { AdminFieldOptions } from './admin-field.js';
|
|
6
|
+
import type { TypedClassDecorator } from './typed.js';
|
|
6
7
|
export interface AdminSettingsPageOptions<T extends object = any> {
|
|
7
8
|
/** `'Payments'` or `{ en: 'Payments', fa: 'پرداخت' }`. Defaults to the humanized page name. */
|
|
8
9
|
label?: LocalizedText;
|
|
@@ -63,5 +64,5 @@ export interface AdminSettingsPageDefinition extends AdminSettingsPageOptions {
|
|
|
63
64
|
* `save` (`AdminSettingsSource`). Viewing it needs `page.<name>`, saving `page.<name>.update`. The name is letters,
|
|
64
65
|
* digits, `-` and `_`, and not the name of a resource.
|
|
65
66
|
*/
|
|
66
|
-
export declare function AdminSettingsPage<T extends object>(name: string, options: AdminSettingsPageOptions<T>):
|
|
67
|
+
export declare function AdminSettingsPage<T extends object>(name: string, options: AdminSettingsPageOptions<T>): TypedClassDecorator<AdminSettingsSource<T>>;
|
|
67
68
|
export declare function getAdminSettingsPageDefinition(target: Function): AdminSettingsPageDefinition | undefined;
|
|
@@ -2,6 +2,7 @@ import 'reflect-metadata';
|
|
|
2
2
|
import type { WidgetData, WidgetParams, WidgetType } from '../contract.js';
|
|
3
3
|
import type { LocalizedText } from '../i18n/localized-text.js';
|
|
4
4
|
import type { AdminContext } from '../resource/admin-context.js';
|
|
5
|
+
import type { TypedClassDecorator } from './typed.js';
|
|
5
6
|
export interface AdminWidgetOptions {
|
|
6
7
|
type: WidgetType;
|
|
7
8
|
title: LocalizedText;
|
|
@@ -23,5 +24,5 @@ export interface AdminWidgetDefinition extends AdminWidgetOptions {
|
|
|
23
24
|
name: string;
|
|
24
25
|
}
|
|
25
26
|
/** A dashboard widget: a provider whose `load` answers its data. The dashboard replaces the home page once one exists. */
|
|
26
|
-
export declare function AdminWidget(name: string, options: AdminWidgetOptions):
|
|
27
|
+
export declare function AdminWidget(name: string, options: AdminWidgetOptions): TypedClassDecorator<AdminWidgetSource>;
|
|
27
28
|
export declare function getAdminWidgetDefinition(target: Function): AdminWidgetDefinition | undefined;
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import 'reflect-metadata';
|
|
2
|
+
import type { AdminContext } from '../resource/admin-context.js';
|
|
3
|
+
import type { ReturnsNothing, RowOf } from './typed.js';
|
|
2
4
|
export type HookKind = 'beforeSave' | 'afterSave' | 'beforeDelete';
|
|
3
5
|
export type SaveMode = 'create' | 'update';
|
|
4
6
|
/** `soft`: moved to the trash (@DeleteDateColumn); `hard`: the row is removed (no trash, or a purge). */
|
|
5
7
|
export type DeleteMode = 'soft' | 'hard';
|
|
6
|
-
/** `(
|
|
7
|
-
|
|
8
|
-
/** `(
|
|
9
|
-
export declare const
|
|
10
|
-
/** `(entity, ctx, mode
|
|
11
|
-
export declare const
|
|
8
|
+
/** A hook decorator: the method takes `(first, ctx, mode)` and returns nothing (sync or async). */
|
|
9
|
+
type HookDecorator<First, Mode> = <P extends object, T extends (first: First extends 'row' ? RowOf<P> : any, ctx: AdminContext, mode: Mode) => unknown>(target: P, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T> & ReturnsNothing<T>) => void;
|
|
10
|
+
/** `(dto, ctx, mode)` — runs before the default create/update saves; may mutate `dto`. Returns nothing. */
|
|
11
|
+
export declare const BeforeSave: () => HookDecorator<'dto', SaveMode>;
|
|
12
|
+
/** `(entity, ctx, mode)` — runs after the default create/update saved. Returns nothing. */
|
|
13
|
+
export declare const AfterSave: () => HookDecorator<'row', SaveMode>;
|
|
14
|
+
/** `(entity, ctx, mode: DeleteMode)` — runs before the default delete and purge; throw to refuse. Returns nothing. */
|
|
15
|
+
export declare const BeforeDelete: () => HookDecorator<'row', DeleteMode>;
|
|
12
16
|
export declare function getHooks(target: Function, kind: HookKind): Array<string | symbol>;
|
|
17
|
+
export {};
|
package/dist/decorators/hooks.js
CHANGED
|
@@ -15,11 +15,11 @@ function hook(kind) {
|
|
|
15
15
|
Reflect.defineMetadata(ADMIN_HOOKS_METADATA, table, owner);
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
-
/** `(dto, ctx, mode)` — runs before the default create/update saves; may mutate `dto`. */
|
|
18
|
+
/** `(dto, ctx, mode)` — runs before the default create/update saves; may mutate `dto`. Returns nothing. */
|
|
19
19
|
export const BeforeSave = () => hook('beforeSave');
|
|
20
|
-
/** `(entity, ctx, mode)` — runs after the default create/update saved. */
|
|
20
|
+
/** `(entity, ctx, mode)` — runs after the default create/update saved. Returns nothing. */
|
|
21
21
|
export const AfterSave = () => hook('afterSave');
|
|
22
|
-
/** `(entity, ctx, mode: DeleteMode)` — runs before the default delete and purge; throw to refuse. */
|
|
22
|
+
/** `(entity, ctx, mode: DeleteMode)` — runs before the default delete and purge; throw to refuse. Returns nothing. */
|
|
23
23
|
export const BeforeDelete = () => hook('beforeDelete');
|
|
24
24
|
export function getHooks(target, kind) {
|
|
25
25
|
return Reflect.getMetadata(ADMIN_HOOKS_METADATA, target)?.[kind] ?? [];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AdminContext } from '../resource/admin-context.js';
|
|
2
|
+
import type { AdminResourceBase } from '../resource/admin-resource-base.js';
|
|
3
|
+
/** A value or a Promise of it. */
|
|
4
|
+
export type Awaitable<T> = T | Promise<T>;
|
|
5
|
+
/**
|
|
6
|
+
* A method decorator that only accepts methods of the signature `M`: decorating a method that takes or returns
|
|
7
|
+
* something else is a compile error, at the decorator.
|
|
8
|
+
*/
|
|
9
|
+
export type TypedMethodDecorator<M> = <T extends M>(target: object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => void;
|
|
10
|
+
/** A class decorator that only accepts classes whose instances are `I`. */
|
|
11
|
+
export type TypedClassDecorator<I> = <C extends abstract new (...args: any[]) => I>(target: C) => void;
|
|
12
|
+
/** The row type of a resource class (`AdminResourceBase<Order>` → `Order`); `any` outside one. */
|
|
13
|
+
export type RowOf<P> = P extends AdminResourceBase<infer T, any> ? T : any;
|
|
14
|
+
/** Refuses (at compile time) a method that returns a value where nothing is read. */
|
|
15
|
+
export type ReturnsNothing<M> = M extends (...args: any[]) => infer R ? [Awaited<R>] extends [void | undefined] ? unknown : {
|
|
16
|
+
'nest-my-admin: this method must return nothing (its value would be ignored)': never;
|
|
17
|
+
} : unknown;
|
|
18
|
+
/** A method of a resource whose first parameter is one of its rows. */
|
|
19
|
+
export type RecordMethodDecorator<Rest extends unknown[], R> = <P extends object, T extends (record: RowOf<P>, ...rest: Rest) => R>(target: P, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => void;
|
|
20
|
+
export type { AdminContext };
|
package/dist/files/file-owner.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { parseRecordId, recordIdOf } from '../crud/record-id.js';
|
|
2
2
|
import { AdminBadRequestError, AdminForbiddenError, AdminNotFoundError, AdminValidationError } from '../errors.js';
|
|
3
|
+
import { checkFoundRecord } from '../host-contract.js';
|
|
3
4
|
/** A resource as the owner of its records' files: permissions, field levels and row scopes decide. */
|
|
4
5
|
export function resourceFileOwner(entry, policy) {
|
|
5
6
|
const { name } = entry.schema;
|
|
@@ -30,7 +31,7 @@ export function resourceFileOwner(entry, policy) {
|
|
|
30
31
|
return undefined;
|
|
31
32
|
try {
|
|
32
33
|
const id = parseRecordId(recordId, entry.schema);
|
|
33
|
-
const entity = await entry.resource.findOne(id, ctx);
|
|
34
|
+
const entity = checkFoundRecord(await entry.resource.findOne(id, ctx), `${entry.resource.constructor.name}.findOne()`);
|
|
34
35
|
if (!entity)
|
|
35
36
|
return undefined;
|
|
36
37
|
await policy.requireInScope(entry, id, recordId, 'view', ctx); // a findOne override may ignore scopes
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime checks of what host code returns where the admin needs a particular shape (spec: «fail loudly»): a wrong
|
|
3
|
+
* value is a programming error, so it fails the request with a sentence naming the method and what it returned,
|
|
4
|
+
* instead of being misread (an `async` scope read as «no restriction»).
|
|
5
|
+
*/
|
|
6
|
+
/** A Promise or any other thenable. */
|
|
7
|
+
export declare const isThenable: (value: unknown) => value is PromiseLike<unknown>;
|
|
8
|
+
/** A short description of a value for an error message: `a Promise`, `an array`, `the string "x"`, `undefined`. */
|
|
9
|
+
export declare function describeValue(value: unknown): string;
|
|
10
|
+
/** Host code broke its contract: a 500 whose message (logged with the correlation id) says what to fix. */
|
|
11
|
+
export declare class HostContractError extends Error {
|
|
12
|
+
constructor(message: string);
|
|
13
|
+
}
|
|
14
|
+
export declare const isPlainObject: (value: unknown) => value is Record<string, unknown>;
|
|
15
|
+
/** What `findMany` must answer: `{ items: [...], total: number | null }` (and the optional paging fields). */
|
|
16
|
+
export declare function checkFindMany<T>(found: T, where: string): T;
|
|
17
|
+
/** A text: a string, or a plain object of strings by locale (`{ en, fa }`), never a Promise or a class instance. */
|
|
18
|
+
export declare const isLocalizedText: (value: unknown) => boolean;
|
|
19
|
+
/** What `query()` and `relationOptions()` hand back: the query builder, never a Promise of it or nothing. */
|
|
20
|
+
export declare function checkQueryBuilder<Q>(value: Q, where: string): Q;
|
|
21
|
+
/** A list of strings (`resolveRoles`), or nothing. */
|
|
22
|
+
export declare function checkStringList(value: unknown, where: string): string[];
|
|
23
|
+
/** A record a write method answered: an object, or nothing (the admin then reloads it). */
|
|
24
|
+
export declare function checkWriteResult(value: unknown, where: string): unknown;
|
|
25
|
+
/** A record `findOne`/`getUser` answered: an object, or null. */
|
|
26
|
+
export declare function checkFoundRecord<T>(value: T, where: string): T;
|
|
27
|
+
/** A yes/no answer given at once. */
|
|
28
|
+
export declare function checkBoolean(value: unknown, where: string): boolean;
|
|
29
|
+
/** An object of values: a plain object or a class instance, never an array or a Promise. */
|
|
30
|
+
export declare const isRecordObject: (value: unknown) => value is Record<string, unknown>;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime checks of what host code returns where the admin needs a particular shape (spec: «fail loudly»): a wrong
|
|
3
|
+
* value is a programming error, so it fails the request with a sentence naming the method and what it returned,
|
|
4
|
+
* instead of being misread (an `async` scope read as «no restriction»).
|
|
5
|
+
*/
|
|
6
|
+
/** A Promise or any other thenable. */
|
|
7
|
+
export const isThenable = (value) => (typeof value === 'object' || typeof value === 'function') && value !== null && typeof value.then === 'function';
|
|
8
|
+
/** A short description of a value for an error message: `a Promise`, `an array`, `the string "x"`, `undefined`. */
|
|
9
|
+
export function describeValue(value) {
|
|
10
|
+
if (value === undefined)
|
|
11
|
+
return 'undefined';
|
|
12
|
+
if (value === null)
|
|
13
|
+
return 'null';
|
|
14
|
+
if (isThenable(value))
|
|
15
|
+
return 'a Promise (is the method async?)';
|
|
16
|
+
if (Array.isArray(value))
|
|
17
|
+
return 'an array';
|
|
18
|
+
if (typeof value === 'string')
|
|
19
|
+
return `the string ${JSON.stringify(value.length > 40 ? `${value.slice(0, 40)}…` : value)}`;
|
|
20
|
+
if (typeof value === 'function')
|
|
21
|
+
return 'a function';
|
|
22
|
+
if (typeof value === 'object') {
|
|
23
|
+
const name = value.constructor?.name;
|
|
24
|
+
return name && name !== 'Object' ? `a ${name}` : 'an object';
|
|
25
|
+
}
|
|
26
|
+
return `the ${typeof value} ${String(value)}`;
|
|
27
|
+
}
|
|
28
|
+
/** Host code broke its contract: a 500 whose message (logged with the correlation id) says what to fix. */
|
|
29
|
+
export class HostContractError extends Error {
|
|
30
|
+
constructor(message) {
|
|
31
|
+
super(`nest-my-admin: ${message}`);
|
|
32
|
+
this.name = 'HostContractError';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export const isPlainObject = (value) => typeof value === 'object' && value !== null && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
|
|
36
|
+
/** What `findMany` must answer: `{ items: [...], total: number | null }` (and the optional paging fields). */
|
|
37
|
+
export function checkFindMany(found, where) {
|
|
38
|
+
const value = found;
|
|
39
|
+
const fail = (what) => {
|
|
40
|
+
throw new HostContractError(`${where}.findMany() returned ${what}; it answers { items: [...], total: number | null } (inMemoryList(rows, params) builds that from an array)`);
|
|
41
|
+
};
|
|
42
|
+
if (!isPlainObject(value))
|
|
43
|
+
fail(describeValue(found));
|
|
44
|
+
if (!Array.isArray(value.items))
|
|
45
|
+
fail(`items that are ${describeValue(value.items)}`);
|
|
46
|
+
const total = value.total;
|
|
47
|
+
if (total !== null && total !== undefined && (typeof total !== 'number' || !Number.isFinite(total) || total < 0))
|
|
48
|
+
fail(`a total of ${describeValue(total)}`);
|
|
49
|
+
if (value.items.some((item) => typeof item !== "object" || item === null))
|
|
50
|
+
fail('items that are not all records (objects)');
|
|
51
|
+
return found;
|
|
52
|
+
}
|
|
53
|
+
/** A text: a string, or a plain object of strings by locale (`{ en, fa }`), never a Promise or a class instance. */
|
|
54
|
+
export const isLocalizedText = (value) => typeof value === 'string' || (isPlainObject(value) && Object.values(value).every((text) => typeof text === 'string'));
|
|
55
|
+
/** What `query()` and `relationOptions()` hand back: the query builder, never a Promise of it or nothing. */
|
|
56
|
+
export function checkQueryBuilder(value, where) {
|
|
57
|
+
// By shape, not instanceof: a host may resolve its own copy of typeorm.
|
|
58
|
+
const qb = value;
|
|
59
|
+
if (typeof qb === 'object' && qb !== null && typeof qb.andWhere === 'function' && typeof qb.getQuery === 'function')
|
|
60
|
+
return value;
|
|
61
|
+
throw new HostContractError(`${where} must return the query builder (add to the one it was given and return it), but it returned ${describeValue(value)}`);
|
|
62
|
+
}
|
|
63
|
+
/** A list of strings (`resolveRoles`), or nothing. */
|
|
64
|
+
export function checkStringList(value, where) {
|
|
65
|
+
if (value === undefined || value === null)
|
|
66
|
+
return [];
|
|
67
|
+
if (Array.isArray(value) && value.every((item) => typeof item === 'string'))
|
|
68
|
+
return value;
|
|
69
|
+
throw new HostContractError(`${where} must return an array of role names, but it returned ${describeValue(value)}`);
|
|
70
|
+
}
|
|
71
|
+
/** A record a write method answered: an object, or nothing (the admin then reloads it). */
|
|
72
|
+
export function checkWriteResult(value, where) {
|
|
73
|
+
if (value === undefined || value === null || (typeof value === 'object' && !Array.isArray(value) && !isThenable(value)))
|
|
74
|
+
return value;
|
|
75
|
+
throw new HostContractError(`${where} must return the saved record (or nothing, to have it reloaded), but it returned ${describeValue(value)}`);
|
|
76
|
+
}
|
|
77
|
+
/** A record `findOne`/`getUser` answered: an object, or null. */
|
|
78
|
+
export function checkFoundRecord(value, where) {
|
|
79
|
+
if (value === undefined || value === null || (typeof value === 'object' && !Array.isArray(value)))
|
|
80
|
+
return value;
|
|
81
|
+
throw new HostContractError(`${where} must return the record or null, but it returned ${describeValue(value)}`);
|
|
82
|
+
}
|
|
83
|
+
/** A yes/no answer given at once. */
|
|
84
|
+
export function checkBoolean(value, where) {
|
|
85
|
+
if (typeof value === 'boolean')
|
|
86
|
+
return value;
|
|
87
|
+
throw new HostContractError(`${where} must return true or false, but it returned ${describeValue(value)}`);
|
|
88
|
+
}
|
|
89
|
+
/** An object of values: a plain object or a class instance, never an array or a Promise. */
|
|
90
|
+
export const isRecordObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value) && !isThenable(value);
|
|
91
|
+
//# sourceMappingURL=host-contract.js.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BadRequestException, HttpException } from '@nestjs/common';
|
|
2
2
|
import { QueryFailedError } from 'typeorm';
|
|
3
3
|
import { AdminConflictError, AdminError } from '../errors.js';
|
|
4
|
+
import { describeValue } from '../host-contract.js';
|
|
4
5
|
/** Maps any thrown value to the admin error contract. Never leaks messages of 5xx/unknown errors. */
|
|
5
6
|
export function toErrorResponse(error, correlationId, logger, context = {}) {
|
|
6
7
|
const { errorMapper } = context;
|
|
@@ -13,6 +14,9 @@ export function toErrorResponse(error, correlationId, logger, context = {}) {
|
|
|
13
14
|
}
|
|
14
15
|
error = mapped;
|
|
15
16
|
}
|
|
17
|
+
else if (mapped !== undefined) {
|
|
18
|
+
logger.error(`[${correlationId}] nest-my-admin: errorMapper must return an AdminError (AdminFieldError, AdminConflictError…) or undefined, but it returned ${describeValue(mapped)}; the error is answered as unmapped`);
|
|
19
|
+
}
|
|
16
20
|
}
|
|
17
21
|
catch (mapperError) {
|
|
18
22
|
logger.error(`[${correlationId}] errorMapper threw: ${mapperError instanceof Error ? (mapperError.stack ?? mapperError.message) : String(mapperError)}`);
|
package/dist/i18n/texts.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { resolveText } from './localized-text.js';
|
|
2
|
+
import { describeValue, HostContractError } from '../host-contract.js';
|
|
2
3
|
/** The one place host texts are resolved. A `translate` that throws falls back to the declared text, logged once per key (once for all keyless texts). */
|
|
3
4
|
export function createTexts(options, logger) {
|
|
4
5
|
const { translate, locale: defaultLocale } = options;
|
|
@@ -6,10 +7,9 @@ export function createTexts(options, logger) {
|
|
|
6
7
|
return (text, locale) => resolveText(text, locale, defaultLocale);
|
|
7
8
|
const warned = new Set();
|
|
8
9
|
return (text, locale, key) => {
|
|
10
|
+
let answer;
|
|
9
11
|
try {
|
|
10
|
-
|
|
11
|
-
if (typeof answer === 'string' && answer !== '')
|
|
12
|
-
return answer;
|
|
12
|
+
answer = translate(key === undefined ? { text, locale } : { key, text, locale });
|
|
13
13
|
}
|
|
14
14
|
catch (error) {
|
|
15
15
|
// Keyless texts are often built from data (action messages): one warning for all of them keeps this set small.
|
|
@@ -18,6 +18,12 @@ export function createTexts(options, logger) {
|
|
|
18
18
|
warned.add(name);
|
|
19
19
|
logger.warn(`translate threw for "${name}" (${error instanceof Error ? error.message : String(error)}); the declared text is shown`);
|
|
20
20
|
}
|
|
21
|
+
return resolveText(text, locale, defaultLocale);
|
|
22
|
+
}
|
|
23
|
+
if (typeof answer === 'string' && answer !== '')
|
|
24
|
+
return answer;
|
|
25
|
+
if (answer !== undefined && answer !== '') {
|
|
26
|
+
throw new HostContractError(`translate must return a string or undefined at once, but it returned ${describeValue(answer)} for "${key ?? resolveText(text, locale, defaultLocale)}"`);
|
|
21
27
|
}
|
|
22
28
|
return resolveText(text, locale, defaultLocale);
|
|
23
29
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -13,7 +13,8 @@ export type { FieldConfig, FieldsConfig, LayoutConfig, LayoutInlineConfig, Layou
|
|
|
13
13
|
export type { RegisteredInline } from './inlines/inline-config.js';
|
|
14
14
|
export { AdminContext, type AdminWriteContext } from './resource/admin-context.js';
|
|
15
15
|
export { AdminCan, AdminScope, type RecordOperation, type ScopeCondition } from './decorators/admin-scope.js';
|
|
16
|
-
export { AdminAction, type ActionOutcome, type AdminActionOptions } from './decorators/admin-action.js';
|
|
16
|
+
export { AdminAction, type ActionOutcome, type ActionReturn, type AdminActionOptions } from './decorators/admin-action.js';
|
|
17
|
+
export type { Awaitable, RowOf, TypedClassDecorator, TypedMethodDecorator } from './decorators/typed.js';
|
|
17
18
|
export { AdminPrint, type AdminPrintOptions } from './decorators/admin-print.js';
|
|
18
19
|
export { html, raw, escapeHtml, HtmlString } from './print/html.js';
|
|
19
20
|
export { AdminSettingsPage, type AdminSettingsPageOptions, type AdminSettingsSource } from './decorators/admin-settings-page.js';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { checkFindMany, checkQueryBuilder } from '../host-contract.js';
|
|
1
2
|
import { recordIdOf } from '../crud/record-id.js';
|
|
2
3
|
import { AdminResourceBase } from '../resource/admin-resource-base.js';
|
|
3
4
|
/**
|
|
@@ -43,7 +44,7 @@ export class InlineReader {
|
|
|
43
44
|
count: 'none',
|
|
44
45
|
pagination: 'offset',
|
|
45
46
|
};
|
|
46
|
-
const found = await child.resource.findMany(params, ctx);
|
|
47
|
+
const found = checkFindMany(await child.resource.findMany(params, ctx), child.className);
|
|
47
48
|
if (child.resource.findMany !== AdminResourceBase.prototype.findMany)
|
|
48
49
|
return this.overridden(inline, value, found, ctx);
|
|
49
50
|
const truncated = found.hasMore === true || found.items.length > inline.max;
|
|
@@ -85,7 +86,7 @@ export class InlineReader {
|
|
|
85
86
|
const { child } = inline;
|
|
86
87
|
const manager = ctx.manager ?? child.dataSource.manager; // a source has no relation, so it is never an inline child
|
|
87
88
|
const qb = manager.getRepository(child.metadata.target).createQueryBuilder('nma_inline');
|
|
88
|
-
return this.deps.policy.applyScopes(child.resource.query(qb, ctx), child, 'view', ctx).andWhere(`nma_inline.${inline.link} = :nmaInlineParent`, { nmaInlineParent: value });
|
|
89
|
+
return this.deps.policy.applyScopes(checkQueryBuilder(child.resource.query(qb, ctx), `${child.className}.query()`), child, 'view', ctx).andWhere(`nma_inline.${inline.link} = :nmaInlineParent`, { nmaInlineParent: value });
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
92
|
//# sourceMappingURL=inline-reader.js.map
|
|
@@ -7,6 +7,7 @@ import { validateWrite } from '../crud/validate-write.js';
|
|
|
7
7
|
import { AdminBadRequestError, AdminError, AdminForbiddenError, AdminForbiddenFieldsError, AdminNotFoundError, AdminValidationError } from '../errors.js';
|
|
8
8
|
import { codeForStatus, hostError, toErrorResponse } from '../http/error-response.js';
|
|
9
9
|
import { MAX_INLINE_ROWS } from '../schema/field-config.js';
|
|
10
|
+
import { checkQueryBuilder, checkFoundRecord } from '../host-contract.js';
|
|
10
11
|
const KEY = /^.{1,64}$/su;
|
|
11
12
|
const isObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
12
13
|
/**
|
|
@@ -154,7 +155,7 @@ export class InlineWriter {
|
|
|
154
155
|
const children = () => {
|
|
155
156
|
const manager = tx.manager ?? child.dataSource.manager; // a source has no relation, so it is never an inline child
|
|
156
157
|
const qb = manager.getRepository(child.metadata.target).createQueryBuilder('nma_child');
|
|
157
|
-
const restricted = policy.applyScopes(child.resource.query(qb, tx), child, 'view', tx);
|
|
158
|
+
const restricted = policy.applyScopes(checkQueryBuilder(child.resource.query(qb, tx), `${child.className}.query()`), child, 'view', tx);
|
|
158
159
|
return restricted.andWhere(`nma_child.${inline.link} = :nmaInlineParent`, { nmaInlineParent: linkValue });
|
|
159
160
|
};
|
|
160
161
|
// The order list is checked against the rows the user sees, and decides which of them move.
|
|
@@ -223,7 +224,7 @@ export class InlineWriter {
|
|
|
223
224
|
// Then each row as the child's own PATCH and DELETE read it: its findOne (an override may refuse a row or load
|
|
224
225
|
// more). That entity is what @AdminCan, readonlyIf, relationOptions() values and the participants see.
|
|
225
226
|
for (const [canonical, entry] of named) {
|
|
226
|
-
const entity = await child.resource.findOne(entry.id, tx);
|
|
227
|
+
const entity = checkFoundRecord(await child.resource.findOne(entry.id, tx), `${child.resource.constructor.name}.findOne()`);
|
|
227
228
|
if (!entity)
|
|
228
229
|
throw notFound(entry.raw);
|
|
229
230
|
rows.set(canonical, entity);
|
package/dist/options.js
CHANGED
|
@@ -2,6 +2,7 @@ import { createTexts } from './i18n/texts.js';
|
|
|
2
2
|
import { Logger } from '@nestjs/common';
|
|
3
3
|
import { checkCurrency } from './schema/currency.js';
|
|
4
4
|
import { DEFAULT_MAX_FILE_BYTES, MAX_FILE_BYTES } from './schema/field-config.js';
|
|
5
|
+
import { describeValue, HostContractError } from './host-contract.js';
|
|
5
6
|
export function resolveAdminOptions(options = {}) {
|
|
6
7
|
const raw = (options.path ?? '/admin').trim();
|
|
7
8
|
const path = '/' + raw.replace(/^\/+|\/+$/g, '');
|
|
@@ -110,7 +111,28 @@ function checkFiles(files) {
|
|
|
110
111
|
throw new Error(`nest-my-admin: files.maxBytes must be at most ${MAX_FILE_BYTES} bytes (2 GiB - 1)`);
|
|
111
112
|
if (files.sanitizeHtml !== undefined && typeof files.sanitizeHtml !== 'function')
|
|
112
113
|
throw new Error('nest-my-admin: files.sanitizeHtml must be a function');
|
|
113
|
-
return { ...files, maxBytes };
|
|
114
|
+
return { ...files, maxBytes, storage: checkedStorage(files.storage) };
|
|
115
|
+
}
|
|
116
|
+
/** The host's storage, with its answers checked where a wrong one would pass unnoticed (an async publicUrl). */
|
|
117
|
+
function checkedStorage(storage) {
|
|
118
|
+
const checked = Object.create(storage);
|
|
119
|
+
checked.publicUrl = (key) => {
|
|
120
|
+
const url = storage.publicUrl(key);
|
|
121
|
+
if (url === undefined || typeof url === 'string')
|
|
122
|
+
return url;
|
|
123
|
+
throw new HostContractError(`files.storage.publicUrl() must return a URL or undefined at once, but it returned ${describeValue(url)}`);
|
|
124
|
+
};
|
|
125
|
+
checked.get = async (key) => {
|
|
126
|
+
const object = await storage.get(key);
|
|
127
|
+
if (object === null || object === undefined)
|
|
128
|
+
return null;
|
|
129
|
+
const found = object;
|
|
130
|
+
if (typeof found !== 'object' || typeof found.body?.pipe !== 'function' || typeof found.contentType !== 'string' || typeof found.size !== 'number') {
|
|
131
|
+
throw new HostContractError(`files.storage.get() must return { body: Readable, contentType, size } or null, but it returned ${describeValue(object)}`);
|
|
132
|
+
}
|
|
133
|
+
return object;
|
|
134
|
+
};
|
|
135
|
+
return checked;
|
|
114
136
|
}
|
|
115
137
|
function checkAudit(audit) {
|
|
116
138
|
if (!audit)
|
|
@@ -23,6 +23,7 @@ import { ResourceRegistry, memberOrder } from '../registry/resource-registry.js'
|
|
|
23
23
|
import { buildDtoForm, nestedProtected } from '../schema/dto-form.js';
|
|
24
24
|
import { checkLayout } from '../schema/field-config.js';
|
|
25
25
|
import { humanize } from '../schema/humanize.js';
|
|
26
|
+
import { describeValue, HostContractError, isRecordObject } from '../host-contract.js';
|
|
26
27
|
/** Page names that are a segment of other permission codes: `page.update` would read as an operation. */
|
|
27
28
|
const RESERVED_NAMES = RESERVED_PAGE_NAMES;
|
|
28
29
|
/** Options that mean something on a resource's field only. */
|
|
@@ -171,8 +172,8 @@ export const unknownPage = (name) => new AdminNotFoundError(`Unknown page "${nam
|
|
|
171
172
|
/** The page's stored values, as its `load()` gives them (secrets included: callers decide what leaves). */
|
|
172
173
|
export async function loadPage(page, ctx) {
|
|
173
174
|
const values = await page.source.load(ctx);
|
|
174
|
-
if (
|
|
175
|
-
throw new
|
|
175
|
+
if (!isRecordObject(values))
|
|
176
|
+
throw new HostContractError(`${page.className}.load() must return an object of the page's values, but it returned ${describeValue(values)}`);
|
|
176
177
|
return values;
|
|
177
178
|
}
|
|
178
179
|
//# sourceMappingURL=page-registry.js.map
|
|
@@ -17,6 +17,7 @@ import { Brackets } from 'typeorm';
|
|
|
17
17
|
import { ADMIN_OPTIONS } from '../constants.js';
|
|
18
18
|
import { recordIdOf } from '../crud/record-id.js';
|
|
19
19
|
import { getCanRules, getScopes } from '../decorators/admin-scope.js';
|
|
20
|
+
import { checkBoolean, checkStringList, describeValue, HostContractError, isPlainObject, isThenable } from '../host-contract.js';
|
|
20
21
|
import { AdminForbiddenError, AdminForbiddenFieldsError, AdminNotFoundError } from '../errors.js';
|
|
21
22
|
import { AdminAuthService } from '../auth/auth.service.js';
|
|
22
23
|
import { PageRegistry, unknownPage } from '../pages/page-registry.js';
|
|
@@ -80,16 +81,20 @@ let AdminPolicy = class AdminPolicy {
|
|
|
80
81
|
if (!user || user.isSuperuser)
|
|
81
82
|
return user ? OPEN : new EffectivePermissions([], false);
|
|
82
83
|
let names = [];
|
|
84
|
+
let fromOptions;
|
|
85
|
+
let fromAdapter;
|
|
83
86
|
try {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
names = [...fromOptions, ...fromAdapter, ...stored];
|
|
87
|
+
fromOptions = await this.options.resolveRoles?.(user);
|
|
88
|
+
fromAdapter = await this.auth.adapter?.resolveRoles?.(user);
|
|
89
|
+
names = await this.rbac.assignedRoleNames(String(user.id));
|
|
88
90
|
}
|
|
89
91
|
catch (error) {
|
|
90
92
|
this.warnOnce(`resolveRoles threw for user ${String(user.id)} (${error instanceof Error ? error.message : String(error)}); the user gets no roles`);
|
|
91
93
|
names = [];
|
|
94
|
+
fromOptions = fromAdapter = undefined;
|
|
92
95
|
}
|
|
96
|
+
// Outside the try: a wrong answer is the host's bug, not a failed lookup («no roles» would hide it).
|
|
97
|
+
names = [...checkStringList(fromOptions, 'the resolveRoles option'), ...checkStringList(fromAdapter, 'the auth adapter\'s resolveRoles()'), ...names];
|
|
93
98
|
const roles = [];
|
|
94
99
|
let known;
|
|
95
100
|
try {
|
|
@@ -472,20 +477,29 @@ let AdminPolicy = class AdminPolicy {
|
|
|
472
477
|
return this.globalScopes(entry, perms).map((scope) => scope.name);
|
|
473
478
|
}
|
|
474
479
|
globalScopes(entry, perms) {
|
|
475
|
-
return this.options.globalScopes.filter((scope) => !(scope.exemptSuperusers && perms.superuser) && (scope.appliesTo ? scope.appliesTo({ name: entry.schema.name, entity: entry.entity, metadata: entry.metadata }) : true));
|
|
480
|
+
return this.options.globalScopes.filter((scope) => !(scope.exemptSuperusers && perms.superuser) && (scope.appliesTo ? checkBoolean(scope.appliesTo({ name: entry.schema.name, entity: entry.entity, metadata: entry.metadata }), `global scope "${scope.name}" appliesTo()`) : true));
|
|
476
481
|
}
|
|
477
482
|
callScope(entry, name, ctx) {
|
|
478
483
|
const key = getScopes(entry.resource.constructor)[name];
|
|
479
|
-
|
|
484
|
+
const condition = entry.resource[key].call(entry.resource, ctx);
|
|
485
|
+
// An `async` scope would be read as an empty column map, «no restriction»: refuse it.
|
|
486
|
+
if (isThenable(condition) || !(typeof condition === 'function' || isPlainObject(condition))) {
|
|
487
|
+
throw new HostContractError(`${entry.className}.${String(key)} (@AdminScope("${name}")) returned ${describeValue(condition)}; a scope answers at once with a column map or a function (it cannot be async)`);
|
|
488
|
+
}
|
|
489
|
+
return condition;
|
|
480
490
|
}
|
|
481
491
|
/** A scope's result as SQL: a column map (array = IN, null = IS NULL, undefined = no rows) or a callback. */
|
|
482
492
|
condition(where, alias, entry, condition, what) {
|
|
483
493
|
if (typeof condition === 'function') {
|
|
484
|
-
|
|
494
|
+
// Conditions added after the query ran would restrict nothing: the callback cannot be async either.
|
|
495
|
+
const added = condition(where, alias);
|
|
496
|
+
if (isThenable(added))
|
|
497
|
+
throw new HostContractError(`${entry.className}: the callback of ${what} returned a Promise; it adds its conditions at once (it cannot be async)`);
|
|
485
498
|
return;
|
|
486
499
|
}
|
|
487
|
-
|
|
488
|
-
|
|
500
|
+
// An `async` scope gives a Promise, which would read as an empty column map: «no restriction».
|
|
501
|
+
if (!isPlainObject(condition))
|
|
502
|
+
throw new HostContractError(`${entry.className}: ${what} returned ${describeValue(condition)}; it must answer at once with a column map or a function (it cannot be async)`);
|
|
489
503
|
const entries = Object.entries(condition);
|
|
490
504
|
if (entries.length === 0) {
|
|
491
505
|
where.where('1 = 1');
|
|
@@ -532,14 +546,19 @@ let AdminPolicy = class AdminPolicy {
|
|
|
532
546
|
recordRule(entry, operation, entity, ctx) {
|
|
533
547
|
const methods = entry.resource;
|
|
534
548
|
for (const key of getCanRules(entry.resource.constructor, operation)) {
|
|
549
|
+
let answer;
|
|
535
550
|
try {
|
|
536
|
-
|
|
537
|
-
return false;
|
|
551
|
+
answer = methods[key].call(entry.resource, entity, ctx);
|
|
538
552
|
}
|
|
539
553
|
catch (error) {
|
|
540
554
|
this.warnOnce(`${entry.className}.${String(key)} (@AdminCan("${operation}")) threw: ${error instanceof Error ? error.message : String(error)}; the answer is no`);
|
|
541
555
|
return false;
|
|
542
556
|
}
|
|
557
|
+
// An `async` rule (a Promise) or a forgotten return (undefined) would quietly mean «no» everywhere.
|
|
558
|
+
if (typeof answer !== 'boolean')
|
|
559
|
+
throw new HostContractError(`${entry.className}.${String(key)} (@AdminCan("${operation}")) returned ${describeValue(answer)}; a rule answers at once with true or false (it cannot be async)`);
|
|
560
|
+
if (!answer)
|
|
561
|
+
return false;
|
|
543
562
|
}
|
|
544
563
|
return true;
|
|
545
564
|
}
|