1.0.58 • Published 12 months ago

tech-spec v1.0.58

Weekly downloads
-
License
ISC
Repository
github
Last release
12 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.58

12 months ago

1.0.55

2 years ago

1.0.57

2 years ago

1.0.56

2 years ago

1.0.53

2 years ago

1.0.52

2 years ago

1.0.51

2 years ago

1.0.50

2 years ago

1.0.49

2 years ago

1.0.47

2 years ago

1.0.46

2 years ago

1.0.45

2 years ago

1.0.44

2 years ago

1.0.43

2 years ago

1.0.42

2 years ago

1.0.41

2 years ago

1.0.40

2 years ago

1.0.39

2 years ago

1.0.38

2 years ago

1.0.37

2 years ago

1.0.36

2 years ago

1.0.35

2 years ago

1.0.34

2 years ago

1.0.33

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.22

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago