@kyyinfinite/lumina 1.0.0 → 1.0.2

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 (40) hide show
  1. package/package.json +1 -1
  2. package/src/builders/ai-rich.js +0 -165
  3. package/src/builders/base.js +4 -51
  4. package/src/builders/button-v2.js +13 -78
  5. package/src/builders/button.js +20 -234
  6. package/src/builders/card.js +9 -76
  7. package/src/builders/carousel.js +4 -61
  8. package/src/builders/index.js +1 -7
  9. package/src/builders/sticker.js +102 -0
  10. package/src/client/bot.js +28 -153
  11. package/src/client/connection.js +4 -111
  12. package/src/errors.js +0 -37
  13. package/src/index.d.ts +1 -28
  14. package/src/index.js +23 -121
  15. package/src/media/fetch.js +2 -33
  16. package/src/media/image.js +1 -41
  17. package/src/media/resolver.js +3 -55
  18. package/src/media/sticker.js +124 -0
  19. package/src/media/uploader.js +0 -30
  20. package/src/media/video.js +1 -39
  21. package/src/parsers/code-tokenizer-keywords.js +0 -12
  22. package/src/parsers/code-tokenizer.js +0 -42
  23. package/src/parsers/index.js +0 -7
  24. package/src/parsers/inline-entity.js +8 -117
  25. package/src/parsers/table-metadata.js +1 -35
  26. package/src/proto/enums.js +9 -65
  27. package/src/proto/layouts.js +3 -64
  28. package/src/proto/primitives.js +4 -91
  29. package/src/proto/relay-nodes.js +1 -32
  30. package/src/proto/rich-response.js +6 -57
  31. package/src/proto/updater.js +0 -85
  32. package/src/services/index.js +0 -7
  33. package/src/services/media-service.js +1 -102
  34. package/src/services/message-service.js +16 -158
  35. package/src/services/proto-service.js +3 -57
  36. package/src/utils/id.js +0 -25
  37. package/src/utils/logger.js +2 -39
  38. package/src/utils/mime.js +17 -73
  39. package/src/utils/promise.js +0 -26
  40. package/src/utils/validator.js +6 -71
@@ -1,72 +1,29 @@
1
- /**
2
- * @file validator.js
3
- * @module lumina/utils/validator
4
- *
5
- * Centralised input validators. Every "must be a plain object" check that
6
- * was duplicated 5x in `_build-m.js` is now `ensurePlainObject` / `ensureObjectOrArray`.
7
- */
8
-
9
1
  import { ValidationError } from '../errors.js'
10
2
 
11
- /**
12
- * @param {unknown} v
13
- * @returns {boolean} True when `v` is a non-null, non-array plain object.
14
- */
15
3
  export function isPlainObject(v) {
16
4
  return typeof v === 'object' && v !== null && !Array.isArray(v)
17
5
  }
18
6
 
19
- /**
20
- * @param {unknown} v
21
- * @param {string} label Human-readable field name for the error message.
22
- * @throws {ValidationError} When `v` is not a plain object.
23
- */
24
7
  export function ensurePlainObject(v, label) {
25
8
  if (!isPlainObject(v)) {
26
- throw new ValidationError(`${label} must be a plain object`, {
27
- code: 'LUMINA_VALIDATION_NOT_OBJECT',
28
- })
9
+ throw new ValidationError(`${label} must be a plain object`, { code: 'LUMINA_VALIDATION_NOT_OBJECT' })
29
10
  }
30
11
  }
31
12
 
32
- /**
33
- * @param {unknown} v
34
- * @param {string} label
35
- * @throws {ValidationError}
36
- */
37
13
  export function ensureString(v, label) {
38
14
  if (typeof v !== 'string') {
39
- throw new ValidationError(`${label} must be a string`, {
40
- code: 'LUMINA_VALIDATION_NOT_STRING',
41
- })
15
+ throw new ValidationError(`${label} must be a string`, { code: 'LUMINA_VALIDATION_NOT_STRING' })
42
16
  }
43
17
  }
44
18
 
45
- /**
46
- * @param {unknown} v
47
- * @param {string} label
48
- * @throws {ValidationError}
49
- */
50
19
  export function ensureStringArray(v, label) {
51
20
  if (!Array.isArray(v) || !v.every((x) => typeof x === 'string')) {
52
- throw new ValidationError(`${label} must be an array of strings`, {
53
- code: 'LUMINA_VALIDATION_NOT_STRING_ARRAY',
54
- })
21
+ throw new ValidationError(`${label} must be an array of strings`, { code: 'LUMINA_VALIDATION_NOT_STRING_ARRAY' })
55
22
  }
56
23
  }
57
24
 
58
- /**
59
- * Accept either a plain object OR an array of plain objects.
60
- * Replaces the duplicated validation block in AIRich.addReels/addProduct/addPost.
61
- *
62
- * @param {unknown} v
63
- * @param {string} label
64
- * @throws {ValidationError}
65
- */
66
25
  export function ensureObjectOrArray(v, label) {
67
- const ok =
68
- isPlainObject(v) ||
69
- (Array.isArray(v) && v.every((x) => isPlainObject(x)))
26
+ const ok = isPlainObject(v) || (Array.isArray(v) && v.every((x) => isPlainObject(x)))
70
27
  if (!ok) {
71
28
  throw new ValidationError(`${label} must be a plain object or an array of plain objects`, {
72
29
  code: 'LUMINA_VALIDATION_NOT_OBJECT_OR_ARRAY',
@@ -74,40 +31,18 @@ export function ensureObjectOrArray(v, label) {
74
31
  }
75
32
  }
76
33
 
77
- /**
78
- * @param {unknown} v
79
- * @param {string} label
80
- * @throws {ValidationError}
81
- */
82
34
  export function ensureBuffer(v, label) {
83
35
  if (!Buffer.isBuffer(v)) {
84
- throw new ValidationError(`${label} must be a Buffer`, {
85
- code: 'LUMINA_VALIDATION_NOT_BUFFER',
86
- })
36
+ throw new ValidationError(`${label} must be a Buffer`, { code: 'LUMINA_VALIDATION_NOT_BUFFER' })
87
37
  }
88
38
  }
89
39
 
90
- /**
91
- * @param {unknown} v
92
- * @param {string} label
93
- * @throws {ValidationError}
94
- */
95
40
  export function ensureStringOrBuffer(v, label) {
96
41
  if (typeof v !== 'string' && !Buffer.isBuffer(v)) {
97
- throw new ValidationError(`${label} must be a string or Buffer`, {
98
- code: 'LUMINA_VALIDATION_NOT_STRING_OR_BUFFER',
99
- })
42
+ throw new ValidationError(`${label} must be a string or Buffer`, { code: 'LUMINA_VALIDATION_NOT_STRING_OR_BUFFER' })
100
43
  }
101
44
  }
102
45
 
103
- /**
104
- * Coerce "anything that looks like media" into a uniform source descriptor.
105
- * Replaces the `Buffer.isBuffer(path) ? path : { url: path }` pattern that
106
- * was duplicated 5x across the legacy Button setters.
107
- *
108
- * @param {string | Buffer | object} source
109
- * @returns {{ buffer?: Buffer, url?: string, raw: object }}
110
- */
111
46
  export function coerceMediaSource(source) {
112
47
  if (Buffer.isBuffer(source)) return { buffer: source, raw: source }
113
48
  if (typeof source === 'string') return { url: source, raw: { url: source } }