@smartsoft001/core

@smartsoft001/core installs the packages every project uses, whatever it is built with: the model decorators, the domain contracts, the helpers and the shared DTOs.


Install

npm install @smartsoft001/core

What it is

It ships no code of its own. It exists so a project can pull the framework-agnostic half of the framework with one command and at one version, instead of naming ten packages and keeping their versions aligned by hand.

Nothing in it knows about Angular, NestJS or a database, which is what makes it the part a frontend written in something else can reuse unchanged.

Usage

After installing, use the packages directly. A model decorated with @Field is the starting point of almost everything else:

import {
  castModel,
  Field,
  FieldType,
  getInvalidFields,
  Model,
} from '@smartsoft001/models';

@Model({ titleKey: 'name' })
export class Product {
  id?: string;

  // `required` declared inside the `create` block applies to the create mode
  // only. A bare `create: true` would mark the field as editable on create but
  // would also reset the top level `required` flag back to "not required".
  @Field({ type: FieldType.text, create: { required: true } })
  name?: string;

  @Field({ type: FieldType.currency, create: true })
  price?: number;

  // No `create` block, so `castModel` removes it from a create payload.
  @Field({ type: FieldType.text })
  internalNote?: string;
}

/** Returns the keys of the fields required on create that are still empty. */
export function missingFields(product: Product): Array<string> {
  return getInvalidFields(product, 'create', []);
}

/**
 * Strips everything that must not reach the create endpoint.
 * `castModel` mutates the object in place, so the example copies it first. It
 * keeps `id` plus every field marked for the mode, and deletes the rest,
 * including properties that carry no `@Field` decorator at all.
 */
export function toCreatePayload(product: Product): Product {
  const payload = Object.assign(new Product(), product);

  castModel(payload, 'create', []);

  return payload;
}

API

None of its own. The package is a manifest with pinned dependencies, so what it brings is its whole interface:

Package
@smartsoft001/models
@smartsoft001/domain-core
@smartsoft001/utils
@smartsoft001/users
@smartsoft001/auth-domain
@smartsoft001/crud-domain
@smartsoft001/crud-shell-dtos
@smartsoft001/auth-shell-dtos
@smartsoft001/crud-shell-app-services
@smartsoft001/auth-shell-app-services

Every version is pinned exactly, so the set installs at one version and a release never leaves two of these packages on different ones.

Migrations

This package also carries the framework's migrations, because every stack depends on it and therefore every project has it. npx nx migrate @smartsoft001/core@latest fetches a release and writes down what it wants to change; npx nx migrate --run-migrations performs it. Upgrading describes what the migrations can do and what is left to check by hand.

Every stack depends on this package, so installing angular-stack or nestjs-stack brings it too.