plugin-build-guide-block 1.1.5 → 1.1.7

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 (123) hide show
  1. package/client-v2.d.ts +2 -0
  2. package/client-v2.js +1 -0
  3. package/dist/client/index.js +2 -2
  4. package/dist/client-v2/73.6b8b2eda7d969c69.js +10 -0
  5. package/dist/client-v2/index.js +10 -0
  6. package/dist/externalVersion.js +9 -8
  7. package/dist/node_modules/sanitize-html/index.js +2 -2
  8. package/dist/node_modules/sanitize-html/package.json +1 -1
  9. package/dist/server/actions/build.js +687 -85
  10. package/dist/server/collections/ai-build-guide-spaces.js +20 -0
  11. package/dist/server/plugin.js +21 -19
  12. package/dist/server/tools/search-guides.js +41 -30
  13. package/package.json +7 -3
  14. package/src/client/components/BuildButton.tsx +20 -9
  15. package/src/client-v2/plugin.tsx +24 -0
  16. package/src/server/actions/build.ts +774 -88
  17. package/src/server/collections/ai-build-guide-spaces.ts +77 -57
  18. package/src/server/plugin.ts +170 -163
  19. package/src/server/tools/search-guides.ts +113 -95
  20. package/dist/client/UserGuideBlock.d.ts +0 -2
  21. package/dist/client/UserGuideBlockInitializer.d.ts +0 -2
  22. package/dist/client/UserGuideBlockProvider.d.ts +0 -2
  23. package/dist/client/UserGuideManager.d.ts +0 -2
  24. package/dist/client/components/BuildButton.d.ts +0 -2
  25. package/dist/client/components/LLMServiceSelect.d.ts +0 -2
  26. package/dist/client/components/ModelSelect.d.ts +0 -2
  27. package/dist/client/components/SpaceSelect.d.ts +0 -2
  28. package/dist/client/components/StatusTag.d.ts +0 -2
  29. package/dist/client/locale.d.ts +0 -3
  30. package/dist/client/models/UserGuideBlockModel.d.ts +0 -9
  31. package/dist/client/models/index.d.ts +0 -9
  32. package/dist/client/plugin.d.ts +0 -5
  33. package/dist/client/schemaSettings.d.ts +0 -2
  34. package/dist/client/schemas/spacesSchema.d.ts +0 -437
  35. package/dist/index.d.ts +0 -2
  36. package/dist/locale/namespace.d.ts +0 -6
  37. package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.browser.cjs +0 -34
  38. package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.browser.js +0 -34
  39. package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.cjs +0 -35
  40. package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.d.ts +0 -56
  41. package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.js +0 -35
  42. package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.native.js +0 -26
  43. package/dist/node_modules/sanitize-html/node_modules/nanoid/async/package.json +0 -12
  44. package/dist/node_modules/sanitize-html/node_modules/nanoid/bin/nanoid.cjs +0 -55
  45. package/dist/node_modules/sanitize-html/node_modules/nanoid/index.browser.cjs +0 -34
  46. package/dist/node_modules/sanitize-html/node_modules/nanoid/index.browser.js +0 -34
  47. package/dist/node_modules/sanitize-html/node_modules/nanoid/index.cjs +0 -45
  48. package/dist/node_modules/sanitize-html/node_modules/nanoid/index.d.cts +0 -91
  49. package/dist/node_modules/sanitize-html/node_modules/nanoid/index.d.ts +0 -91
  50. package/dist/node_modules/sanitize-html/node_modules/nanoid/index.js +0 -45
  51. package/dist/node_modules/sanitize-html/node_modules/nanoid/nanoid.js +0 -1
  52. package/dist/node_modules/sanitize-html/node_modules/nanoid/non-secure/index.cjs +0 -21
  53. package/dist/node_modules/sanitize-html/node_modules/nanoid/non-secure/index.d.ts +0 -33
  54. package/dist/node_modules/sanitize-html/node_modules/nanoid/non-secure/index.js +0 -21
  55. package/dist/node_modules/sanitize-html/node_modules/nanoid/non-secure/package.json +0 -6
  56. package/dist/node_modules/sanitize-html/node_modules/nanoid/package.json +0 -88
  57. package/dist/node_modules/sanitize-html/node_modules/nanoid/url-alphabet/index.cjs +0 -3
  58. package/dist/node_modules/sanitize-html/node_modules/nanoid/url-alphabet/index.js +0 -3
  59. package/dist/node_modules/sanitize-html/node_modules/nanoid/url-alphabet/package.json +0 -6
  60. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/at-rule.d.ts +0 -115
  61. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/at-rule.js +0 -25
  62. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/comment.d.ts +0 -67
  63. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/comment.js +0 -13
  64. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/container.d.ts +0 -452
  65. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/container.js +0 -439
  66. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/css-syntax-error.d.ts +0 -248
  67. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/css-syntax-error.js +0 -100
  68. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/declaration.d.ts +0 -148
  69. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/declaration.js +0 -24
  70. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/document.d.ts +0 -68
  71. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/document.js +0 -33
  72. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/fromJSON.d.ts +0 -9
  73. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/fromJSON.js +0 -54
  74. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/input.d.ts +0 -194
  75. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/input.js +0 -248
  76. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/lazy-result.d.ts +0 -190
  77. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/lazy-result.js +0 -550
  78. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/list.d.ts +0 -57
  79. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/list.js +0 -58
  80. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/map-generator.js +0 -359
  81. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/no-work-result.d.ts +0 -46
  82. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/no-work-result.js +0 -135
  83. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/node.d.ts +0 -536
  84. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/node.js +0 -381
  85. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/parse.d.ts +0 -9
  86. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/parse.js +0 -42
  87. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/parser.js +0 -610
  88. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/postcss.d.mts +0 -72
  89. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/postcss.d.ts +0 -441
  90. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/postcss.js +0 -101
  91. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/previous-map.d.ts +0 -81
  92. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/previous-map.js +0 -142
  93. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/processor.d.ts +0 -115
  94. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/processor.js +0 -67
  95. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/result.d.ts +0 -206
  96. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/result.js +0 -42
  97. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/root.d.ts +0 -86
  98. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/root.js +0 -61
  99. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/rule.d.ts +0 -113
  100. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/rule.js +0 -27
  101. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/stringifier.d.ts +0 -46
  102. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/stringifier.js +0 -353
  103. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/stringify.d.ts +0 -9
  104. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/stringify.js +0 -11
  105. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/symbols.js +0 -5
  106. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/terminal-highlight.js +0 -70
  107. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/tokenize.js +0 -266
  108. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/warn-once.js +0 -13
  109. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/warning.d.ts +0 -147
  110. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/warning.js +0 -37
  111. package/dist/node_modules/sanitize-html/node_modules/postcss/node_modules/.bin/nanoid +0 -15
  112. package/dist/node_modules/sanitize-html/node_modules/postcss/node_modules/.bin/nanoid.cmd +0 -7
  113. package/dist/node_modules/sanitize-html/node_modules/postcss/package.json +0 -88
  114. package/dist/server/actions/build.d.ts +0 -2
  115. package/dist/server/actions/getHtml.d.ts +0 -2
  116. package/dist/server/actions/getMarkdown.d.ts +0 -2
  117. package/dist/server/collections/ai-build-guide-pages.d.ts +0 -2
  118. package/dist/server/collections/ai-build-guide-spaces.d.ts +0 -2
  119. package/dist/server/index.d.ts +0 -2
  120. package/dist/server/plugin.d.ts +0 -16
  121. package/dist/server/tools/index.d.ts +0 -1
  122. package/dist/server/tools/search-guides.d.ts +0 -28
  123. /package/{dist/client/index.d.ts → src/client-v2/index.tsx} +0 -0
@@ -1,437 +0,0 @@
1
- export declare const MIN_TARGET_CHAPTER_COUNT = 1;
2
- export declare const MAX_TARGET_CHAPTER_COUNT = 12;
3
- export declare const DEFAULT_TARGET_CHAPTER_COUNT = 5;
4
- export declare const spacesSchema: {
5
- type: string;
6
- name: string;
7
- properties: {
8
- card: {
9
- type: string;
10
- 'x-component': string;
11
- 'x-decorator': string;
12
- 'x-decorator-props': {
13
- collection: string;
14
- action: string;
15
- rowKey: string;
16
- params: {
17
- appends: string[];
18
- sort: string[];
19
- };
20
- };
21
- properties: {
22
- actions: {
23
- type: string;
24
- 'x-component': string;
25
- 'x-component-props': {
26
- style: {
27
- marginBottom: number;
28
- };
29
- };
30
- properties: {
31
- create: {
32
- type: string;
33
- 'x-component': string;
34
- 'x-component-props': {
35
- type: string;
36
- title: string;
37
- icon: string;
38
- };
39
- properties: {
40
- drawer: {
41
- type: string;
42
- 'x-component': string;
43
- 'x-component-props': {
44
- title: string;
45
- };
46
- properties: {
47
- form: {
48
- type: string;
49
- 'x-component': string;
50
- 'x-use-component-props': string;
51
- properties: {
52
- title: {
53
- type: string;
54
- title: string;
55
- required: boolean;
56
- 'x-decorator': string;
57
- 'x-component': string;
58
- };
59
- llmService: {
60
- type: string;
61
- title: string;
62
- required: boolean;
63
- 'x-decorator': string;
64
- 'x-component': string;
65
- };
66
- model: {
67
- type: string;
68
- title: string;
69
- required: boolean;
70
- 'x-decorator': string;
71
- 'x-component': string;
72
- 'x-reactions': {
73
- dependencies: string[];
74
- fulfill: {
75
- state: {
76
- value: string;
77
- };
78
- };
79
- };
80
- };
81
- outputFormat: {
82
- type: string;
83
- title: string;
84
- required: boolean;
85
- default: string;
86
- 'x-decorator': string;
87
- 'x-component': string;
88
- enum: {
89
- label: string;
90
- value: string;
91
- }[];
92
- };
93
- targetChapterCount: {
94
- type: string;
95
- title: string;
96
- required: boolean;
97
- default: number;
98
- 'x-decorator': string;
99
- 'x-component': string;
100
- 'x-component-props': {
101
- min: number;
102
- max: number;
103
- precision: number;
104
- style: {
105
- width: string;
106
- };
107
- };
108
- };
109
- chapterGuidance: {
110
- type: string;
111
- title: string;
112
- 'x-decorator': string;
113
- 'x-component': string;
114
- 'x-component-props': {
115
- rows: number;
116
- placeholder: string;
117
- };
118
- };
119
- systemPrompt: {
120
- type: string;
121
- title: string;
122
- 'x-decorator': string;
123
- 'x-component': string;
124
- 'x-component-props': {
125
- rows: number;
126
- };
127
- default: string;
128
- };
129
- documents: {
130
- type: string;
131
- title: string;
132
- 'x-decorator': string;
133
- 'x-component': string;
134
- 'x-component-props': {
135
- multiple: boolean;
136
- action: string;
137
- maxCount: number;
138
- };
139
- };
140
- footer: {
141
- type: string;
142
- 'x-component': string;
143
- properties: {
144
- cancel: {
145
- type: string;
146
- title: string;
147
- 'x-component': string;
148
- 'x-use-component-props': string;
149
- };
150
- submit: {
151
- type: string;
152
- title: string;
153
- 'x-component': string;
154
- 'x-use-component-props': string;
155
- };
156
- };
157
- };
158
- };
159
- };
160
- };
161
- };
162
- };
163
- };
164
- };
165
- };
166
- table: {
167
- type: string;
168
- 'x-component': string;
169
- 'x-use-component-props': string;
170
- 'x-component-props': {
171
- rowKey: string;
172
- rowSelection: {
173
- type: string;
174
- };
175
- };
176
- properties: {
177
- title: {
178
- type: string;
179
- title: string;
180
- 'x-decorator': string;
181
- 'x-component': string;
182
- properties: {
183
- title: {
184
- type: string;
185
- 'x-component': string;
186
- 'x-read-pretty': boolean;
187
- };
188
- };
189
- };
190
- status: {
191
- type: string;
192
- title: string;
193
- 'x-decorator': string;
194
- 'x-component': string;
195
- properties: {
196
- status: {
197
- type: string;
198
- 'x-component': string;
199
- 'x-read-pretty': boolean;
200
- };
201
- };
202
- };
203
- buildPhase: {
204
- type: string;
205
- title: string;
206
- 'x-decorator': string;
207
- 'x-component': string;
208
- properties: {
209
- buildPhase: {
210
- type: string;
211
- 'x-component': string;
212
- 'x-read-pretty': boolean;
213
- };
214
- };
215
- };
216
- pageCount: {
217
- type: string;
218
- title: string;
219
- 'x-decorator': string;
220
- 'x-component': string;
221
- properties: {
222
- pageCount: {
223
- type: string;
224
- 'x-component': string;
225
- 'x-read-pretty': boolean;
226
- };
227
- };
228
- };
229
- buildLog: {
230
- type: string;
231
- title: string;
232
- 'x-decorator': string;
233
- 'x-component': string;
234
- properties: {
235
- buildLog: {
236
- type: string;
237
- 'x-component': string;
238
- 'x-read-pretty': boolean;
239
- };
240
- };
241
- };
242
- actions: {
243
- type: string;
244
- title: string;
245
- 'x-decorator': string;
246
- 'x-component': string;
247
- properties: {
248
- actions: {
249
- type: string;
250
- 'x-component': string;
251
- 'x-component-props': {
252
- split: string;
253
- };
254
- properties: {
255
- build: {
256
- type: string;
257
- 'x-component': string;
258
- };
259
- update: {
260
- type: string;
261
- title: string;
262
- 'x-component': string;
263
- 'x-component-props': {
264
- type: string;
265
- };
266
- properties: {
267
- drawer: {
268
- type: string;
269
- 'x-component': string;
270
- 'x-component-props': {
271
- title: string;
272
- };
273
- properties: {
274
- form: {
275
- type: string;
276
- 'x-component': string;
277
- 'x-use-component-props': string;
278
- properties: {
279
- title: {
280
- type: string;
281
- title: string;
282
- required: boolean;
283
- 'x-decorator': string;
284
- 'x-component': string;
285
- };
286
- llmService: {
287
- type: string;
288
- title: string;
289
- required: boolean;
290
- 'x-decorator': string;
291
- 'x-component': string;
292
- };
293
- model: {
294
- type: string;
295
- title: string;
296
- required: boolean;
297
- 'x-decorator': string;
298
- 'x-component': string;
299
- };
300
- outputFormat: {
301
- type: string;
302
- title: string;
303
- required: boolean;
304
- 'x-decorator': string;
305
- 'x-component': string;
306
- enum: {
307
- label: string;
308
- value: string;
309
- }[];
310
- };
311
- targetChapterCount: {
312
- type: string;
313
- title: string;
314
- required: boolean;
315
- default: number;
316
- 'x-decorator': string;
317
- 'x-component': string;
318
- 'x-component-props': {
319
- min: number;
320
- max: number;
321
- precision: number;
322
- style: {
323
- width: string;
324
- };
325
- };
326
- };
327
- chapterGuidance: {
328
- type: string;
329
- title: string;
330
- 'x-decorator': string;
331
- 'x-component': string;
332
- 'x-component-props': {
333
- rows: number;
334
- placeholder: string;
335
- };
336
- };
337
- systemPrompt: {
338
- type: string;
339
- title: string;
340
- 'x-decorator': string;
341
- 'x-component': string;
342
- 'x-component-props': {
343
- rows: number;
344
- };
345
- };
346
- documents: {
347
- type: string;
348
- title: string;
349
- 'x-decorator': string;
350
- 'x-component': string;
351
- 'x-component-props': {
352
- multiple: boolean;
353
- action: string;
354
- maxCount: number;
355
- };
356
- };
357
- generatedHtml: {
358
- type: string;
359
- title: string;
360
- 'x-decorator': string;
361
- 'x-component': string;
362
- 'x-component-props': {
363
- rows: number;
364
- };
365
- 'x-read-pretty': boolean;
366
- };
367
- generatedMarkdown: {
368
- type: string;
369
- title: string;
370
- 'x-decorator': string;
371
- 'x-component': string;
372
- 'x-component-props': {
373
- rows: number;
374
- };
375
- 'x-read-pretty': boolean;
376
- 'x-reactions': {
377
- dependencies: string[];
378
- fulfill: {
379
- state: {
380
- visible: string;
381
- };
382
- };
383
- };
384
- };
385
- buildLog: {
386
- type: string;
387
- title: string;
388
- 'x-decorator': string;
389
- 'x-component': string;
390
- 'x-read-pretty': boolean;
391
- };
392
- footer: {
393
- type: string;
394
- 'x-component': string;
395
- properties: {
396
- cancel: {
397
- type: string;
398
- title: string;
399
- 'x-component': string;
400
- 'x-use-component-props': string;
401
- };
402
- submit: {
403
- type: string;
404
- title: string;
405
- 'x-component': string;
406
- 'x-use-component-props': string;
407
- };
408
- };
409
- };
410
- };
411
- };
412
- };
413
- };
414
- };
415
- };
416
- delete: {
417
- type: string;
418
- title: string;
419
- 'x-component': string;
420
- 'x-use-component-props': string;
421
- 'x-component-props': {
422
- confirm: {
423
- title: string;
424
- content: string;
425
- };
426
- };
427
- };
428
- };
429
- };
430
- };
431
- };
432
- };
433
- };
434
- };
435
- };
436
- };
437
- };
package/dist/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './server';
2
- export { default } from './server';
@@ -1,6 +0,0 @@
1
- /**
2
- * Shared namespace constant.
3
- * Matches the namespace already used in inline schema strings
4
- * such as {{t("...", { ns: "build-guide-block" })}}.
5
- */
6
- export declare const name = "build-guide-block";
@@ -1,34 +0,0 @@
1
- let random = async bytes => crypto.getRandomValues(new Uint8Array(bytes))
2
- let customAlphabet = (alphabet, defaultSize = 21) => {
3
- let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
4
- let step = -~((1.6 * mask * defaultSize) / alphabet.length)
5
- return async (size = defaultSize) => {
6
- let id = ''
7
- while (true) {
8
- let bytes = crypto.getRandomValues(new Uint8Array(step))
9
- let i = step
10
- while (i--) {
11
- id += alphabet[bytes[i] & mask] || ''
12
- if (id.length === size) return id
13
- }
14
- }
15
- }
16
- }
17
- let nanoid = async (size = 21) => {
18
- let id = ''
19
- let bytes = crypto.getRandomValues(new Uint8Array(size))
20
- while (size--) {
21
- let byte = bytes[size] & 63
22
- if (byte < 36) {
23
- id += byte.toString(36)
24
- } else if (byte < 62) {
25
- id += (byte - 26).toString(36).toUpperCase()
26
- } else if (byte < 63) {
27
- id += '_'
28
- } else {
29
- id += '-'
30
- }
31
- }
32
- return id
33
- }
34
- module.exports = { nanoid, customAlphabet, random }
@@ -1,34 +0,0 @@
1
- let random = async bytes => crypto.getRandomValues(new Uint8Array(bytes))
2
- let customAlphabet = (alphabet, defaultSize = 21) => {
3
- let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
4
- let step = -~((1.6 * mask * defaultSize) / alphabet.length)
5
- return async (size = defaultSize) => {
6
- let id = ''
7
- while (true) {
8
- let bytes = crypto.getRandomValues(new Uint8Array(step))
9
- let i = step
10
- while (i--) {
11
- id += alphabet[bytes[i] & mask] || ''
12
- if (id.length === size) return id
13
- }
14
- }
15
- }
16
- }
17
- let nanoid = async (size = 21) => {
18
- let id = ''
19
- let bytes = crypto.getRandomValues(new Uint8Array(size))
20
- while (size--) {
21
- let byte = bytes[size] & 63
22
- if (byte < 36) {
23
- id += byte.toString(36)
24
- } else if (byte < 62) {
25
- id += (byte - 26).toString(36).toUpperCase()
26
- } else if (byte < 63) {
27
- id += '_'
28
- } else {
29
- id += '-'
30
- }
31
- }
32
- return id
33
- }
34
- export { nanoid, customAlphabet, random }
@@ -1,35 +0,0 @@
1
- let crypto = require('crypto')
2
- let { urlAlphabet } = require('../url-alphabet/index.cjs')
3
- let random = bytes =>
4
- new Promise((resolve, reject) => {
5
- crypto.randomFill(Buffer.allocUnsafe(bytes), (err, buf) => {
6
- if (err) {
7
- reject(err)
8
- } else {
9
- resolve(buf)
10
- }
11
- })
12
- })
13
- let customAlphabet = (alphabet, defaultSize = 21) => {
14
- let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
15
- let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
16
- let tick = (id, size = defaultSize) =>
17
- random(step).then(bytes => {
18
- let i = step
19
- while (i--) {
20
- id += alphabet[bytes[i] & mask] || ''
21
- if (id.length === size) return id
22
- }
23
- return tick(id, size)
24
- })
25
- return size => tick('', size)
26
- }
27
- let nanoid = (size = 21) =>
28
- random(size).then(bytes => {
29
- let id = ''
30
- while (size--) {
31
- id += urlAlphabet[bytes[size] & 63]
32
- }
33
- return id
34
- })
35
- module.exports = { nanoid, customAlphabet, random }
@@ -1,56 +0,0 @@
1
- /**
2
- * Generate secure URL-friendly unique ID. The non-blocking version.
3
- *
4
- * By default, the ID will have 21 symbols to have a collision probability
5
- * similar to UUID v4.
6
- *
7
- * ```js
8
- * import { nanoid } from 'nanoid/async'
9
- * nanoid().then(id => {
10
- * model.id = id
11
- * })
12
- * ```
13
- *
14
- * @param size Size of the ID. The default size is 21.
15
- * @returns A promise with a random string.
16
- */
17
- export function nanoid(size?: number): Promise<string>
18
-
19
- /**
20
- * A low-level function.
21
- * Generate secure unique ID with custom alphabet. The non-blocking version.
22
- *
23
- * Alphabet must contain 256 symbols or less. Otherwise, the generator
24
- * will not be secure.
25
- *
26
- * @param alphabet Alphabet used to generate the ID.
27
- * @param defaultSize Size of the ID. The default size is 21.
28
- * @returns A function that returns a promise with a random string.
29
- *
30
- * ```js
31
- * import { customAlphabet } from 'nanoid/async'
32
- * const nanoid = customAlphabet('0123456789абвгдеё', 5)
33
- * nanoid().then(id => {
34
- * model.id = id //=> "8ё56а"
35
- * })
36
- * ```
37
- */
38
- export function customAlphabet(
39
- alphabet: string,
40
- defaultSize?: number
41
- ): (size?: number) => Promise<string>
42
-
43
- /**
44
- * Generate an array of random bytes collected from hardware noise.
45
- *
46
- * ```js
47
- * import { random } from 'nanoid/async'
48
- * random(5).then(bytes => {
49
- * bytes //=> [10, 67, 212, 67, 89]
50
- * })
51
- * ```
52
- *
53
- * @param bytes Size of the array.
54
- * @returns A promise with a random bytes array.
55
- */
56
- export function random(bytes: number): Promise<Uint8Array>
@@ -1,35 +0,0 @@
1
- import crypto from 'crypto'
2
- import { urlAlphabet } from '../url-alphabet/index.js'
3
- let random = bytes =>
4
- new Promise((resolve, reject) => {
5
- crypto.randomFill(Buffer.allocUnsafe(bytes), (err, buf) => {
6
- if (err) {
7
- reject(err)
8
- } else {
9
- resolve(buf)
10
- }
11
- })
12
- })
13
- let customAlphabet = (alphabet, defaultSize = 21) => {
14
- let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
15
- let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
16
- let tick = (id, size = defaultSize) =>
17
- random(step).then(bytes => {
18
- let i = step
19
- while (i--) {
20
- id += alphabet[bytes[i] & mask] || ''
21
- if (id.length === size) return id
22
- }
23
- return tick(id, size)
24
- })
25
- return size => tick('', size)
26
- }
27
- let nanoid = (size = 21) =>
28
- random(size).then(bytes => {
29
- let id = ''
30
- while (size--) {
31
- id += urlAlphabet[bytes[size] & 63]
32
- }
33
- return id
34
- })
35
- export { nanoid, customAlphabet, random }