@naturalcycles/js-lib 15.36.0 → 15.38.0

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.
@@ -1,4 +1,4 @@
1
- import type { AnyObject, BaseDBEntity, IsoDate, IsoDateTime, UnixTimestamp } from '../types.js';
1
+ import { type AnyObject, type BaseDBEntity, type IsoDate, type IsoDateTime, type UnixTimestamp } from '../types.js';
2
2
  import type { JsonSchema, JsonSchemaAllOf, JsonSchemaAny, JsonSchemaArray, JsonSchemaBoolean, JsonSchemaConst, JsonSchemaEnum, JsonSchemaNull, JsonSchemaNumber, JsonSchemaObject, JsonSchemaOneOf, JsonSchemaRef, JsonSchemaString, JsonSchemaTuple } from './jsonSchema.model.js';
3
3
  export interface JsonSchemaBuilder<T = unknown> {
4
4
  build: () => JsonSchema<T>;
@@ -9,7 +9,7 @@ export interface JsonSchemaBuilder<T = unknown> {
9
9
  */
10
10
  export declare const j: {
11
11
  any<T = unknown>(): JsonSchemaAnyBuilder<T, JsonSchemaAny<T>, false>;
12
- const<T = unknown>(value: T): JsonSchemaAnyBuilder<T, JsonSchemaConst<T>, false>;
12
+ const<T extends string | number | boolean | null>(value: T): JsonSchemaAnyBuilder<T, JsonSchemaConst<T>, false>;
13
13
  null(): JsonSchemaAnyBuilder<null, JsonSchemaNull, false>;
14
14
  ref<T = unknown>($ref: string): JsonSchemaAnyBuilder<T, JsonSchemaRef<T>, false>;
15
15
  enum<T = unknown>(enumValues: T[]): JsonSchemaAnyBuilder<T, JsonSchemaEnum<T>, false>;
@@ -20,6 +20,7 @@ export declare const j: {
20
20
  unixTimestamp(): JsonSchemaNumberBuilder<UnixTimestamp, false>;
21
21
  unixTimestamp2000(): JsonSchemaNumberBuilder<UnixTimestamp, false>;
22
22
  string<T extends string = string>(): JsonSchemaStringBuilder<T, false>;
23
+ jwt(): JsonSchemaStringBuilder<string, false>;
23
24
  /**
24
25
  * Accepts only the `YYYY-MM-DD` shape from all ISO 8601 variants.
25
26
  */
@@ -125,6 +126,7 @@ export declare class JsonSchemaStringBuilder<T extends string = string, Opt exte
125
126
  * and optionally end with either a `Z` or a `+/-hh:mm` timezone part.
126
127
  */
127
128
  isoDateTime(): JsonSchemaStringBuilder<IsoDateTime>;
129
+ jwt(): this;
128
130
  private transformModify;
129
131
  }
130
132
  export declare class JsonSchemaObjectBuilder<T extends AnyObject, Opt extends boolean = false> extends JsonSchemaAnyBuilder<T, JsonSchemaObject<T>, Opt> {
@@ -1,6 +1,7 @@
1
1
  import { _uniq } from '../array/array.util.js';
2
2
  import { _deepCopy } from '../object/object.util.js';
3
3
  import { _sortObject } from '../object/sortObject.js';
4
+ import { JWT_REGEX, } from '../types.js';
4
5
  import { JSON_SCHEMA_ORDER } from './jsonSchema.cnst.js';
5
6
  import { mergeJsonSchemaObjects } from './jsonSchema.util.js';
6
7
  /**
@@ -56,6 +57,9 @@ export const j = {
56
57
  string() {
57
58
  return new JsonSchemaStringBuilder();
58
59
  },
60
+ jwt() {
61
+ return new JsonSchemaStringBuilder().jwt();
62
+ },
59
63
  /**
60
64
  * Accepts only the `YYYY-MM-DD` shape from all ISO 8601 variants.
61
65
  */
@@ -291,6 +295,9 @@ export class JsonSchemaStringBuilder extends JsonSchemaAnyBuilder {
291
295
  isoDateTime() {
292
296
  return this.format('IsoDateTime').branded().description('IsoDateTime');
293
297
  }
298
+ jwt() {
299
+ return this.regex(JWT_REGEX);
300
+ }
294
301
  transformModify(t, add) {
295
302
  if (add) {
296
303
  this.schema.transform = _uniq([...(this.schema.transform || []), t]);
package/dist/types.d.ts CHANGED
@@ -266,6 +266,7 @@ export type ShortBoolean = '1';
266
266
  export type Base64String = string;
267
267
  export type Base64UrlString = string;
268
268
  export type JWTString = string;
269
+ export declare const JWT_REGEX: RegExp;
269
270
  export type SemVerString = string;
270
271
  /**
271
272
  * Named type for JSON.parse / JSON.stringify second argument
package/dist/types.js CHANGED
@@ -20,6 +20,7 @@ export const _passUndefinedMapper = () => undefined;
20
20
  export const _noop = (..._args) => undefined;
21
21
  export const _passthroughPredicate = () => true;
22
22
  export const _passNothingPredicate = () => false;
23
+ export const JWT_REGEX = /^[\w-]+\.[\w-]+\.[\w-]+$/;
23
24
  /**
24
25
  * Like _stringMapValues, but values are sorted.
25
26
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
3
  "type": "module",
4
- "version": "15.36.0",
4
+ "version": "15.38.0",
5
5
  "dependencies": {
6
6
  "tslib": "^2",
7
7
  "undici": "^7",
@@ -1,7 +1,15 @@
1
1
  import { _uniq } from '../array/array.util.js'
2
2
  import { _deepCopy } from '../object/object.util.js'
3
3
  import { _sortObject } from '../object/sortObject.js'
4
- import type { AnyObject, BaseDBEntity, IsoDate, IsoDateTime, UnixTimestamp } from '../types.js'
4
+ import {
5
+ type AnyObject,
6
+ type BaseDBEntity,
7
+ type IsoDate,
8
+ type IsoDateTime,
9
+ JWT_REGEX,
10
+ type JWTString,
11
+ type UnixTimestamp,
12
+ } from '../types.js'
5
13
  import { JSON_SCHEMA_ORDER } from './jsonSchema.cnst.js'
6
14
  import type {
7
15
  JsonSchema,
@@ -35,7 +43,7 @@ export const j = {
35
43
  any<T = unknown>() {
36
44
  return new JsonSchemaAnyBuilder<T, JsonSchemaAny<T>>({})
37
45
  },
38
- const<T = unknown>(value: T) {
46
+ const<T extends string | number | boolean | null>(value: T) {
39
47
  return new JsonSchemaAnyBuilder<T, JsonSchemaConst<T>>({
40
48
  const: value,
41
49
  })
@@ -82,6 +90,9 @@ export const j = {
82
90
  string<T extends string = string>() {
83
91
  return new JsonSchemaStringBuilder<T>()
84
92
  },
93
+ jwt() {
94
+ return new JsonSchemaStringBuilder<JWTString>().jwt()
95
+ },
85
96
 
86
97
  /**
87
98
  * Accepts only the `YYYY-MM-DD` shape from all ISO 8601 variants.
@@ -384,6 +395,10 @@ export class JsonSchemaStringBuilder<
384
395
  return this.format('IsoDateTime').branded<IsoDateTime>().description('IsoDateTime')
385
396
  }
386
397
 
398
+ jwt(): this {
399
+ return this.regex(JWT_REGEX)
400
+ }
401
+
387
402
  private transformModify(t: 'trim' | 'toLowerCase' | 'toUpperCase', add: boolean): this {
388
403
  if (add) {
389
404
  this.schema.transform = _uniq([...(this.schema.transform || []), t])
package/src/types.ts CHANGED
@@ -335,6 +335,7 @@ export type ShortBoolean = '1'
335
335
  export type Base64String = string
336
336
  export type Base64UrlString = string
337
337
  export type JWTString = string
338
+ export const JWT_REGEX = /^[\w-]+\.[\w-]+\.[\w-]+$/
338
339
 
339
340
  export type SemVerString = string
340
341