@praxisui/specification 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ This package is licensed under the Apache License, Version 2.0.
2
+
3
+ For the full license text, see the repository root LICENSE file:
4
+ ../../LICENSE
5
+
6
+ Apache License 2.0: https://www.apache.org/licenses/LICENSE-2.0
7
+
package/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # @praxisui/specification
2
+
3
+ > Biblioteca TypeScript para criar validações composáveis (Specification Pattern), com DSL legível, serialização JSON, metadados ricos e registries de funções/transformações.
4
+
5
+ ## Visão Geral
6
+
7
+ `@praxisui/specification` provê fábricas e composições para você declarar regras de validação de forma segura e expressiva:
8
+ - Composições booleanas: `and`, `or`, `not`, `xor`, `implies`.
9
+ - Comparações e validações de campos (ex.: `greaterThan`, `contains`, `minLength`).
10
+ - Validadores condicionais (ex.: `requiredIf`).
11
+ - DSL legível e serialização/descrição JSON para persistência.
12
+ - Metadados para mensagens, códigos e configurações de UI.
13
+
14
+ Este pacote é compatível com Angular apps (peer deps Angular), mas pode ser usado em qualquer projeto TypeScript/Node.
15
+
16
+ ## Instalação
17
+
18
+ ```bash
19
+ npm i @praxisui/specification @praxisui/specification-core
20
+ ```
21
+
22
+ Peer dependencies (Angular v20):
23
+ - `@angular/core` `^20.0.0`
24
+ - `@angular/common` `^20.0.0`
25
+
26
+ Dependências em runtime:
27
+ - `@praxisui/specification-core` (instale junto)
28
+ - `tslib` (já vem por padrão em projetos Angular/TS modernos)
29
+
30
+ ## Exemplo Rápido
31
+
32
+ ```ts
33
+ import { SpecificationFactory } from '@praxisui/specification';
34
+
35
+ // Regra: idade > 18, email contém '@' e telefone obrigatório se role == 'admin'
36
+ const userSpec = SpecificationFactory.and(
37
+ SpecificationFactory.greaterThan('age', 18),
38
+ SpecificationFactory.contains('email', '@'),
39
+ SpecificationFactory.requiredIf(
40
+ 'phone',
41
+ SpecificationFactory.equals('role', 'admin')
42
+ )
43
+ );
44
+
45
+ // Validação
46
+ const user = { age: 25, email: 'user@company.com', role: 'admin' };
47
+ const ok = userSpec.isSatisfiedBy(user); // false (faltou phone)
48
+
49
+ // DSL legível
50
+ console.log(userSpec.toDSL());
51
+ // Ex.: age > 18 && contains(email, "@") && requiredIf(phone, role == "admin")
52
+
53
+ // JSON (persistência/transporte)
54
+ const json = userSpec.toJSON();
55
+ ```
56
+
57
+ ## Dicas de Uso
58
+
59
+ - Para regras personalizadas, registre funções: `FunctionRegistry.getInstance().register('isValidCPF', fn)`.
60
+ - Para transformar valores antes da comparação (ex.: upper/trim), use `TransformRegistry`.
61
+ - Para compor validações complexas por formulário/coleção, veja utilitários em `SpecificationFactory`.
62
+
63
+ ## Documentação
64
+
65
+ - Guia detalhado e exemplos: `projects/praxis-specification/docs/README.md`
66
+ - Conceitos (Rules Engines & Specifications): `docs/concepts/rules-engines-and-specifications.md`
67
+
68
+ ## Build local e Publicação
69
+
70
+ ```bash
71
+ # build do pacote
72
+ ng build praxis-specification
73
+
74
+ # gerar tarball para inspeção (dentro do dist)
75
+ cd dist/praxis-specification && npm pack
76
+
77
+ # publicar (exige configuração de token/registry)
78
+ npm publish --access public
79
+ ```
80
+
81
+ O pacote publicado inclui este `README.md` via configuração de `assets` no `ng-package.json`.
82
+
83
+ ## Links
84
+ - Repositório: https://github.com/codexrodrigues/praxis
85
+ - Issues: https://github.com/codexrodrigues/praxis/issues