1.0.57 • Published 5 months ago

tech-spec v1.0.57

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

Tech-Spec

npm version CI codecov Maintainability Test Coverage https://nodei.co/npm/tech-spec.png?downloads=true&downloadRank=true&stars=true

Installation

npm install -g tech-spec

Usage example

techs-spec/some-feature.tech-spec.yaml

type: feature
metadata:
  name: somrt
spec:
  someting:
    type: date
    value: '2023-02-01'
  another:
    type: link
    value: https://google.com
  asd:
    type: string
    value: 'test string'

tech-spec/login.field.tech-spec.yaml

type: field
metadata:
  name: login
spec:
    type: string
    regex: '^[\w_]{4,100}$'

tech-spec/password.field.tech-spec.yaml

type: field
metadata:
  name: password
spec:
  type: string
  regex: '^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]){5;150}$'

tech-spec/registration.form.tech-spec.yaml

type: form
metadata:
  name: Registration
spec:
  login:
    required: true
    fieldRef: login
    helperMessage: null
    errorMessage: null

  password:
    required: true
    fieldRef: password
    errorMessage: 'Invalid'
    helperMessage: null

Command:

techspec generate tech-spec output
❇️  Code is successfully generated

output/form.ts

export const RegistrationForm = {
  login: {
    required: true,
    fieldRef: "login",
    helperMessage: null,
    errorMessage: null,
    field: {
      type: "string",
      regex: new RegExp("^[\\w_]4,100}$")
    }
  },
  password: {
    required: true,
    fieldRef: "password",
    errorMessage: "Invalid",
    helperMessage: null,
    field: {
      type: "string",
      regex: new RegExp("^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]){5;150}$")
    }
  }
};

output/features.ts

export const somrtFeature = {
  someting: {
    type: "date",
    value: new Date("2023-02-01")
  },
  another: {
    type: "link",
    value: new URL("https://google.com")
  },
  asd: {
    type: "string",
    value: "adsa"
  }
};

In your client code:

import { buildValidators, FormValidators, ValidatorError } from 'tech-spec'
import { RegistrationForm } from '<output-dir>/form'

const validators: FormValidators<typeof RegistrationForm> = buildValidators(RegistrationForm)
const result: ValidatorError = validators.login('asd') // login has less characters than required in spec
if (!result.isValid) {
    throw new Error(result.errorMessage)
}

Yaml Parsing Errors Examples

tech-spec/light.theme.tech-spec.yaml

type: theme
metadata:
  name: light
  asd
spec:
  colors:
    check: rgba(255, 255, 255, 255)
techspec validate tech-spec
🚨 YamlParsingError: tech-spec/registration.form.tech-spec.yaml

Reason: bad indentation of a mapping entry

4 | spec:
5 |   login:
6 |     asdasd
7 |     required: true
-----------------^
8 |     fieldRef: login
9 |     helperMessage: null

Types of spec

  • form
  • field
  • DesignSystem
  • feature

Form

type: form

Metadata fields:

  • name: string

Each key in spec mapping represents name of field.

Field mapping keys:

  • required: boolean
  • errorMessage: string | null
  • helperMessage: string | null
  • fieldRef: string (must be the same as field.metadata.name)

Example:

type: form
metadata:
  name: Registration
spec:
  login:
    required: true
    fieldRef: login
    helperMessage: null
    errorMessage: null

  password:
    required: true
    fieldRef: password
    errorMessage: 'Invalid'
    helperMessage: null

Field

type: field

Metadata fields:

  • name: string

Each key in spec mapping represents name of field.

Spec fields:

  • type: 'string'
  • regex: string (valid regex string)

Example:

type: field
metadata:
  name: login
spec:
  type: string
  regex: '^[\w_]4,100}$'

Feature

type: feature

Metadata fields:

  • name: string

Each key in spec mapping represents name of field.

Different types have different configuration options.

Field types and their spec fields

  • type: string

    value: string (any string)

  • type: uint

    value: number (unsigned integer number)

  • type: int

    value: number (signed integer number)

  • type: float

    value: number (number with floating point)

  • type: link

    value: string (http link)

  • type: email

    value: string

  • type: regex

    value: string (valid regex string)

  • type: date

    value: string (date string according to RFC3339)

  • type: time

    value: string (time string according to RFC3339)

  • type: datetime

    value: string (date-time string according to RFC3339)

  • type: duration

    value: string (duration string according to RFC3339)

  • type: uuid

    value: string (valid uuid string according to RFC4122)

Example:

type: feature
metadata:
  name: somrt
spec:
  someting:
    type: date
    value: '2023-02-01'
  another:
    type: link
    value: https://google.com
  asd:
    type: string
    value: 'test string'
1.0.55

6 months ago

1.0.57

5 months ago

1.0.56

6 months ago

1.0.53

8 months ago

1.0.52

8 months ago

1.0.51

8 months ago

1.0.50

8 months ago

1.0.49

8 months ago

1.0.47

8 months ago

1.0.46

8 months ago

1.0.45

8 months ago

1.0.44

8 months ago

1.0.43

8 months ago

1.0.42

9 months ago

1.0.41

9 months ago

1.0.40

9 months ago

1.0.39

9 months ago

1.0.38

9 months ago

1.0.37

9 months ago

1.0.36

9 months ago

1.0.35

9 months ago

1.0.34

9 months ago

1.0.33

9 months ago

1.0.32

9 months ago

1.0.31

9 months ago

1.0.30

9 months ago

1.0.29

9 months ago

1.0.28

9 months ago

1.0.27

9 months ago

1.0.26

9 months ago

1.0.25

9 months ago

1.0.24

9 months ago

1.0.23

10 months ago

1.0.22

10 months ago

1.0.20

10 months ago

1.0.19

10 months ago

1.0.18

10 months ago

1.0.17

10 months ago

1.0.16

10 months ago

1.0.15

10 months ago

1.0.14

10 months ago

1.0.13

10 months ago

1.0.12

10 months ago

1.0.11

10 months ago

1.0.10

10 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago