@strictly/define 0.0.12 → 0.0.14

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.
Files changed (34) hide show
  1. package/.out/transformers/flatteners/json_path.d.ts +6 -2
  2. package/.out/transformers/flatteners/json_path.js +15 -2
  3. package/.out/transformers/flatteners/specs/json_paths.tests.d.ts +1 -0
  4. package/.out/transformers/flatteners/specs/json_paths.tests.js +50 -0
  5. package/.out/tsconfig.tsbuildinfo +1 -1
  6. package/.out/types/builders.d.ts +21 -20
  7. package/.out/types/builders.js +8 -5
  8. package/.out/types/flattened_types_of_validating_type.d.ts +4 -4
  9. package/.out/types/flattened_validators_of_validating_type.d.ts +7 -6
  10. package/.out/types/specs/flattened_validators_of_validating_type.tests.js +2 -2
  11. package/.out/types/validating_definitions.d.ts +14 -12
  12. package/.out/types/validating_type_def_with_error.d.ts +13 -13
  13. package/.out/validation/validator.d.ts +1 -0
  14. package/.out/validation/validator.js +4 -0
  15. package/.out/validation/validators/composite_validator.d.ts +7 -0
  16. package/.out/validation/validators/composite_validator.js +32 -0
  17. package/.turbo/turbo-build.log +8 -8
  18. package/.turbo/turbo-check-types.log +1 -1
  19. package/dist/index.cjs +86 -33
  20. package/dist/index.d.cts +85 -79
  21. package/dist/index.d.ts +85 -79
  22. package/dist/index.js +62 -9
  23. package/package.json +1 -1
  24. package/transformers/flatteners/json_path.ts +44 -4
  25. package/transformers/flatteners/specs/json_paths.tests.ts +69 -0
  26. package/types/builders.ts +46 -26
  27. package/types/flattened_types_of_validating_type.ts +5 -2
  28. package/types/flattened_validators_of_validating_type.ts +7 -9
  29. package/types/specs/builder.tests.ts +31 -31
  30. package/types/specs/flattened_validators_of_validating_type.tests.ts +7 -7
  31. package/types/validating_definitions.ts +27 -15
  32. package/types/validating_type_def_with_error.ts +23 -23
  33. package/validation/validator.ts +21 -0
  34. package/validation/validators/composite_validator.ts +42 -0
@@ -1,2 +1,6 @@
1
- export declare function jsonPath(prefix: string, segment: number | string, qualifier?: string): string;
2
- export declare function jsonPathPop(path: string): [string, string] | null;
1
+ import { type StringConcatOf } from '@strictly/base';
2
+ export declare function jsonPath<Prefix extends string, Segment extends number | string>(prefix: Prefix, segment: Segment): `${Prefix}.${Segment}`;
3
+ export declare function jsonPath<Prefix extends string, Segment extends number | string, Qualifier extends string>(prefix: Prefix, segment: Segment, qualifier: Qualifier): `${Prefix}.${Qualifier}${Segment}`;
4
+ export declare function jsonPathPop<Path extends string>(path: Path): [string, string] | null;
5
+ export declare function jsonPathPrefix<Prefix extends string, Path extends string>(prefix: Prefix, path: Path): Path extends StringConcatOf<'$', infer ToMount> ? `${Prefix}${ToMount}` : never;
6
+ export declare function jsonPathUnprefix<Prefix extends string, Path extends string>(prefix: Prefix, path: Path): Path extends StringConcatOf<Prefix, infer ToUnmount> ? `$${ToUnmount}` : never;
@@ -1,7 +1,10 @@
1
- export function jsonPath(prefix, segment, qualifier = '') {
2
- const s = `.${qualifier}${segment}`;
1
+ import { assertEqual, assertState, } from '@strictly/base';
2
+ export function jsonPath(prefix, segment, qualifier) {
3
+ const s = `.${qualifier !== null && qualifier !== void 0 ? qualifier : ''}${segment}`;
4
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
3
5
  return `${prefix}${s}`;
4
6
  }
7
+ // TODO type safety
5
8
  export function jsonPathPop(path) {
6
9
  const parts = path.split('.');
7
10
  if (parts.length <= 1) {
@@ -12,3 +15,13 @@ export function jsonPathPop(path) {
12
15
  parts.pop(),
13
16
  ];
14
17
  }
18
+ export function jsonPathPrefix(prefix, path) {
19
+ assertEqual(path[0], '$', '{} should start with $', path);
20
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
21
+ return `${prefix}${path.slice(1)}`;
22
+ }
23
+ export function jsonPathUnprefix(prefix, path) {
24
+ assertState(path.startsWith(prefix), '{} should start with {}', path, prefix);
25
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
26
+ return `$${path.slice(prefix.length)}`;
27
+ }
@@ -0,0 +1,50 @@
1
+ import { jsonPath, jsonPathPrefix, jsonPathUnprefix, } from 'transformers/flatteners/json_path';
2
+ describe('json_paths', () => {
3
+ describe('jsonPath', () => {
4
+ describe('simple', () => {
5
+ const path = jsonPath('$', 'thing');
6
+ it('has the expected type', () => {
7
+ expectTypeOf(path).toEqualTypeOf();
8
+ });
9
+ it('has the expected value', () => {
10
+ expect(path).toEqual('$.thing');
11
+ });
12
+ });
13
+ describe('indexed', () => {
14
+ const path = jsonPath(`$.${1}`, 1);
15
+ it('has the expected type', () => {
16
+ expectTypeOf(path).toEqualTypeOf();
17
+ });
18
+ it('has the expected value', () => {
19
+ expect(path).toEqual('$.1.1');
20
+ });
21
+ });
22
+ describe('qualified', () => {
23
+ const path = jsonPath('$', 'x', 'y:');
24
+ it('has the expected type', () => {
25
+ expectTypeOf(path).toEqualTypeOf();
26
+ });
27
+ it('has the expected value', () => {
28
+ expect(path).toEqual('$.y:x');
29
+ });
30
+ });
31
+ });
32
+ describe('jsonPathPrefix', () => {
33
+ const path = jsonPathPrefix('$.x', '$.x.y');
34
+ it('has the expected type', () => {
35
+ expectTypeOf(path).toEqualTypeOf();
36
+ });
37
+ it('has the expected value', () => {
38
+ expect(path).toEqual('$.x.x.y');
39
+ });
40
+ });
41
+ describe('jsonPathUnprefix', () => {
42
+ const path = jsonPathUnprefix('$.x.x.x', '$.x.x.x.x.y');
43
+ it('has the expected type', () => {
44
+ expectTypeOf(path).toEqualTypeOf();
45
+ });
46
+ it('has the expected value', () => {
47
+ expect(path).toEqual('$.x.y');
48
+ });
49
+ });
50
+ });