@naturalcycles/js-lib 14.42.1 → 14.46.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.
Files changed (139) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/dist/index.d.ts +3 -1
  3. package/dist/index.js +7 -3
  4. package/dist/json-schema/from-data/generateJsonSchemaFromData.d.ts +7 -0
  5. package/dist/json-schema/from-data/generateJsonSchemaFromData.js +90 -0
  6. package/dist/json-schema/jsonSchema.model.d.ts +7 -0
  7. package/dist/json-schema/jsonSchemaBuilder.d.ts +3 -0
  8. package/dist/json-schema/jsonSchemaBuilder.js +9 -0
  9. package/dist/string/stringifyAny.d.ts +1 -1
  10. package/dist/string/stringifyAny.js +1 -1
  11. package/dist/typeFest.d.ts +16 -0
  12. package/dist/vendor/is.d.ts +224 -0
  13. package/dist/vendor/is.js +466 -0
  14. package/dist-esm/array/array.util.js +0 -1
  15. package/dist-esm/array/range.js +0 -1
  16. package/dist-esm/decorators/createPromiseDecorator.js +0 -1
  17. package/dist-esm/decorators/debounce.decorator.js +0 -1
  18. package/dist-esm/decorators/debounce.js +0 -1
  19. package/dist-esm/decorators/decorator.util.js +0 -1
  20. package/dist-esm/decorators/logMethod.decorator.js +0 -1
  21. package/dist-esm/decorators/memo.decorator.js +0 -1
  22. package/dist-esm/decorators/memo.util.js +0 -1
  23. package/dist-esm/decorators/memoFn.js +0 -1
  24. package/dist-esm/decorators/memoSimple.decorator.js +0 -1
  25. package/dist-esm/decorators/retry.decorator.js +0 -1
  26. package/dist-esm/decorators/timeout.decorator.js +0 -1
  27. package/dist-esm/error/app.error.js +0 -1
  28. package/dist-esm/error/assert.js +0 -1
  29. package/dist-esm/error/error.model.js +0 -1
  30. package/dist-esm/error/error.util.js +0 -1
  31. package/dist-esm/error/errorMode.js +0 -1
  32. package/dist-esm/error/http.error.js +0 -1
  33. package/dist-esm/error/try.js +0 -1
  34. package/dist-esm/error/tryCatch.js +0 -1
  35. package/dist-esm/index.js +3 -2
  36. package/dist-esm/json-schema/from-data/generateJsonSchemaFromData.js +86 -0
  37. package/dist-esm/json-schema/jsonSchema.cnst.js +0 -1
  38. package/dist-esm/json-schema/jsonSchema.model.js +0 -1
  39. package/dist-esm/json-schema/jsonSchema.util.js +0 -1
  40. package/dist-esm/json-schema/jsonSchemaBuilder.js +9 -1
  41. package/dist-esm/json-schema/jsonSchemas.js +0 -1
  42. package/dist-esm/lodash.types.js +0 -1
  43. package/dist-esm/math/math.util.js +0 -1
  44. package/dist-esm/math/sma.js +0 -1
  45. package/dist-esm/number/createDeterministicRandom.js +0 -1
  46. package/dist-esm/number/number.util.js +0 -1
  47. package/dist-esm/object/deepEquals.js +0 -1
  48. package/dist-esm/object/object.util.js +0 -1
  49. package/dist-esm/object/sortObject.js +0 -1
  50. package/dist-esm/object/sortObjectDeep.js +0 -1
  51. package/dist-esm/promise/AggregatedError.js +0 -1
  52. package/dist-esm/promise/pBatch.js +0 -1
  53. package/dist-esm/promise/pDefer.js +0 -1
  54. package/dist-esm/promise/pDelay.js +0 -1
  55. package/dist-esm/promise/pFilter.js +0 -1
  56. package/dist-esm/promise/pHang.js +0 -1
  57. package/dist-esm/promise/pMap.js +0 -1
  58. package/dist-esm/promise/pProps.js +0 -1
  59. package/dist-esm/promise/pRetry.js +0 -1
  60. package/dist-esm/promise/pState.js +0 -1
  61. package/dist-esm/promise/pTimeout.js +0 -1
  62. package/dist-esm/promise/pTuple.js +0 -1
  63. package/dist-esm/string/case.js +0 -1
  64. package/dist-esm/string/json.util.js +0 -1
  65. package/dist-esm/string/lodash/unicodeWords.js +0 -1
  66. package/dist-esm/string/lodash/words.js +0 -1
  67. package/dist-esm/string/string.util.js +0 -1
  68. package/dist-esm/string/stringifyAny.js +1 -2
  69. package/dist-esm/time/time.util.js +0 -1
  70. package/dist-esm/typeFest.js +0 -1
  71. package/dist-esm/types.js +0 -1
  72. package/dist-esm/unit/size.util.js +0 -1
  73. package/dist-esm/vendor/is.js +463 -0
  74. package/package.json +2 -1
  75. package/src/index.ts +4 -0
  76. package/src/json-schema/from-data/generateJsonSchemaFromData.ts +120 -0
  77. package/src/json-schema/jsonSchema.model.ts +8 -0
  78. package/src/json-schema/jsonSchemaBuilder.ts +16 -10
  79. package/src/string/stringifyAny.ts +2 -2
  80. package/src/typeFest.ts +30 -0
  81. package/src/vendor/is.ts +837 -0
  82. package/dist-esm/array/array.util.js.map +0 -1
  83. package/dist-esm/array/range.js.map +0 -1
  84. package/dist-esm/decorators/createPromiseDecorator.js.map +0 -1
  85. package/dist-esm/decorators/debounce.decorator.js.map +0 -1
  86. package/dist-esm/decorators/debounce.js.map +0 -1
  87. package/dist-esm/decorators/decorator.util.js.map +0 -1
  88. package/dist-esm/decorators/logMethod.decorator.js.map +0 -1
  89. package/dist-esm/decorators/memo.decorator.js.map +0 -1
  90. package/dist-esm/decorators/memo.util.js.map +0 -1
  91. package/dist-esm/decorators/memoFn.js.map +0 -1
  92. package/dist-esm/decorators/memoSimple.decorator.js.map +0 -1
  93. package/dist-esm/decorators/retry.decorator.js.map +0 -1
  94. package/dist-esm/decorators/timeout.decorator.js.map +0 -1
  95. package/dist-esm/error/app.error.js.map +0 -1
  96. package/dist-esm/error/assert.js.map +0 -1
  97. package/dist-esm/error/error.model.js.map +0 -1
  98. package/dist-esm/error/error.util.js.map +0 -1
  99. package/dist-esm/error/errorMode.js.map +0 -1
  100. package/dist-esm/error/http.error.js.map +0 -1
  101. package/dist-esm/error/try.js.map +0 -1
  102. package/dist-esm/error/tryCatch.js.map +0 -1
  103. package/dist-esm/index.js.map +0 -1
  104. package/dist-esm/json-schema/jsonSchema.cnst.js.map +0 -1
  105. package/dist-esm/json-schema/jsonSchema.model.js.map +0 -1
  106. package/dist-esm/json-schema/jsonSchema.util.js.map +0 -1
  107. package/dist-esm/json-schema/jsonSchemaBuilder.js.map +0 -1
  108. package/dist-esm/json-schema/jsonSchemas.js.map +0 -1
  109. package/dist-esm/lodash.types.js.map +0 -1
  110. package/dist-esm/math/math.util.js.map +0 -1
  111. package/dist-esm/math/sma.js.map +0 -1
  112. package/dist-esm/number/createDeterministicRandom.js.map +0 -1
  113. package/dist-esm/number/number.util.js.map +0 -1
  114. package/dist-esm/object/deepEquals.js.map +0 -1
  115. package/dist-esm/object/object.util.js.map +0 -1
  116. package/dist-esm/object/sortObject.js.map +0 -1
  117. package/dist-esm/object/sortObjectDeep.js.map +0 -1
  118. package/dist-esm/promise/AggregatedError.js.map +0 -1
  119. package/dist-esm/promise/pBatch.js.map +0 -1
  120. package/dist-esm/promise/pDefer.js.map +0 -1
  121. package/dist-esm/promise/pDelay.js.map +0 -1
  122. package/dist-esm/promise/pFilter.js.map +0 -1
  123. package/dist-esm/promise/pHang.js.map +0 -1
  124. package/dist-esm/promise/pMap.js.map +0 -1
  125. package/dist-esm/promise/pProps.js.map +0 -1
  126. package/dist-esm/promise/pRetry.js.map +0 -1
  127. package/dist-esm/promise/pState.js.map +0 -1
  128. package/dist-esm/promise/pTimeout.js.map +0 -1
  129. package/dist-esm/promise/pTuple.js.map +0 -1
  130. package/dist-esm/string/case.js.map +0 -1
  131. package/dist-esm/string/json.util.js.map +0 -1
  132. package/dist-esm/string/lodash/unicodeWords.js.map +0 -1
  133. package/dist-esm/string/lodash/words.js.map +0 -1
  134. package/dist-esm/string/string.util.js.map +0 -1
  135. package/dist-esm/string/stringifyAny.js.map +0 -1
  136. package/dist-esm/time/time.util.js.map +0 -1
  137. package/dist-esm/typeFest.js.map +0 -1
  138. package/dist-esm/types.js.map +0 -1
  139. package/dist-esm/unit/size.util.js.map +0 -1
@@ -61,6 +61,11 @@ export const jsonSchema = {
61
61
  type: 'boolean',
62
62
  })
63
63
  },
64
+ buffer() {
65
+ return new JsonSchemaAnyBuilder<Buffer, JsonSchemaAny<Buffer>>({
66
+ instanceof: 'Buffer',
67
+ })
68
+ },
64
69
 
65
70
  // number types
66
71
  number() {
@@ -81,18 +86,14 @@ export const jsonSchema = {
81
86
  },
82
87
  // email: () => new JsonSchemaStringBuilder().email(),
83
88
  // complex types
84
- object<T extends Record<any, any>>(
85
- props: {
86
- [k in keyof T]: JsonSchemaAnyBuilder<T[k]>
87
- },
88
- ) {
89
+ object<T extends Record<any, any>>(props: {
90
+ [k in keyof T]: JsonSchemaAnyBuilder<T[k]>
91
+ }) {
89
92
  return new JsonSchemaObjectBuilder<T>().addProperties(props)
90
93
  },
91
- rootObject<T extends Record<any, any>>(
92
- props: {
93
- [k in keyof T]: JsonSchemaAnyBuilder<T[k]>
94
- },
95
- ) {
94
+ rootObject<T extends Record<any, any>>(props: {
95
+ [k in keyof T]: JsonSchemaAnyBuilder<T[k]>
96
+ }) {
96
97
  return new JsonSchemaObjectBuilder<T>().addProperties(props).$schemaDraft7()
97
98
  },
98
99
  array<ITEM = unknown>(itemSchema: JsonSchemaAnyBuilder<ITEM>) {
@@ -166,6 +167,11 @@ export class JsonSchemaAnyBuilder<T = unknown, SCHEMA_TYPE extends JsonSchema<T>
166
167
  return this
167
168
  }
168
169
 
170
+ instanceof(of: string): this {
171
+ this.schema.instanceof = of
172
+ return this
173
+ }
174
+
169
175
  optional(optional = true): this {
170
176
  if (optional) {
171
177
  this.schema.optionalField = true
@@ -9,7 +9,7 @@ const jsonStringifyFn: JsonStringifyFunction = (obj, reviver, space) =>
9
9
 
10
10
  export interface StringifyAnyOptions {
11
11
  /**
12
- * @default 1000
12
+ * @default 10_000
13
13
  * Default limit is less than in Node, cause it's likely to be used e.g in Browser alert()
14
14
  */
15
15
  maxLen?: number
@@ -128,7 +128,7 @@ export function _stringifyAny(obj: any, opt: StringifyAnyOptions = {}): string {
128
128
  if (s === undefined) return 'undefined'
129
129
 
130
130
  // Handle maxLen
131
- const { maxLen = 1000 } = opt
131
+ const { maxLen = 10_000 } = opt
132
132
  if (maxLen && s.length > maxLen) {
133
133
  s = s.slice(0, maxLen) + `... ${Math.ceil(s.length / 1024)} KB message truncated`
134
134
  }
package/src/typeFest.ts CHANGED
@@ -288,3 +288,33 @@ export type ConditionalPick<Base, Condition> = Pick<Base, ConditionalKeys<Base,
288
288
  @category Basic
289
289
  */
290
290
  export type Class<T = any> = new (...args: any[]) => T
291
+
292
+ /**
293
+ Matches any [typed array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray), like `Uint8Array` or `Float64Array`.
294
+ */
295
+ export type TypedArray =
296
+ | Int8Array
297
+ | Uint8Array
298
+ | Uint8ClampedArray
299
+ | Int16Array
300
+ | Uint16Array
301
+ | Int32Array
302
+ | Uint32Array
303
+ | Float32Array
304
+ | Float64Array
305
+ | BigInt64Array
306
+ | BigUint64Array
307
+
308
+ declare global {
309
+ interface SymbolConstructor {
310
+ readonly observable: symbol
311
+ }
312
+ }
313
+
314
+ /**
315
+ Matches a value that is like an [Observable](https://github.com/tc39/proposal-observable).
316
+ */
317
+ export interface ObservableLike {
318
+ subscribe(observer: (value: unknown) => void): void
319
+ [Symbol.observable](): ObservableLike
320
+ }