@xsai/stream-object 0.4.0-beta.5 → 0.4.0-beta.6

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.
package/dist/index.d.ts CHANGED
@@ -1,96 +1,6 @@
1
1
  import { StreamTextOptions, StreamTextResult } from '@xsai/stream-text';
2
2
  import { Schema, Infer } from 'xsschema';
3
3
 
4
- /**
5
- Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
6
-
7
- @category Type
8
- */
9
- type Primitive =
10
- | null
11
- | undefined
12
- | string
13
- | number
14
- | boolean
15
- | symbol
16
- | bigint;
17
-
18
- declare global {
19
- // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
20
- interface SymbolConstructor {
21
- readonly observable: symbol;
22
- }
23
- }
24
-
25
- /**
26
- Extract all optional keys from the given type.
27
-
28
- This is useful when you want to create a new type that contains different type values for the optional keys only.
29
-
30
- @example
31
- ```
32
- import type {OptionalKeysOf, Except} from 'type-fest';
33
-
34
- interface User {
35
- name: string;
36
- surname: string;
37
-
38
- luckyNumber?: number;
39
- }
40
-
41
- const REMOVE_FIELD = Symbol('remove field symbol');
42
- type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
43
- [Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
44
- };
45
-
46
- const update1: UpdateOperation<User> = {
47
- name: 'Alice'
48
- };
49
-
50
- const update2: UpdateOperation<User> = {
51
- name: 'Bob',
52
- luckyNumber: REMOVE_FIELD
53
- };
54
- ```
55
-
56
- @category Utilities
57
- */
58
- type OptionalKeysOf<BaseType extends object> =
59
- BaseType extends unknown // For distributing `BaseType`
60
- ? (keyof {
61
- [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never
62
- }) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
63
- : never; // Should never happen
64
-
65
- /**
66
- Extract all required keys from the given type.
67
-
68
- This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
69
-
70
- @example
71
- ```
72
- import type {RequiredKeysOf} from 'type-fest';
73
-
74
- declare function createValidation<Entity extends object, Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>>(field: Key, validator: (value: Entity[Key]) => boolean): ValidatorFn;
75
-
76
- interface User {
77
- name: string;
78
- surname: string;
79
-
80
- luckyNumber?: number;
81
- }
82
-
83
- const validator1 = createValidation<User>('name', value => value.length < 25);
84
- const validator2 = createValidation<User>('surname', value => value.length < 25);
85
- ```
86
-
87
- @category Utilities
88
- */
89
- type RequiredKeysOf<BaseType extends object> =
90
- BaseType extends unknown // For distributing `BaseType`
91
- ? Exclude<keyof BaseType, OptionalKeysOf<BaseType>>
92
- : never; // Should never happen
93
-
94
4
  /**
95
5
  Returns a boolean for whether the given type is `never`.
96
6
 
@@ -191,6 +101,20 @@ const anyA = get(anyObject, 'a');
191
101
  */
192
102
  type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
193
103
 
104
+ /**
105
+ Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
106
+
107
+ @category Type
108
+ */
109
+ type Primitive =
110
+ | null
111
+ | undefined
112
+ | string
113
+ | number
114
+ | boolean
115
+ | symbol
116
+ | bigint;
117
+
194
118
  /**
195
119
  Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
196
120
 
@@ -250,6 +174,75 @@ fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface`
250
174
  */
251
175
  type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};
252
176
 
177
+ /**
178
+ Extract all optional keys from the given type.
179
+
180
+ This is useful when you want to create a new type that contains different type values for the optional keys only.
181
+
182
+ @example
183
+ ```
184
+ import type {OptionalKeysOf, Except} from 'type-fest';
185
+
186
+ interface User {
187
+ name: string;
188
+ surname: string;
189
+
190
+ luckyNumber?: number;
191
+ }
192
+
193
+ const REMOVE_FIELD = Symbol('remove field symbol');
194
+ type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
195
+ [Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
196
+ };
197
+
198
+ const update1: UpdateOperation<User> = {
199
+ name: 'Alice'
200
+ };
201
+
202
+ const update2: UpdateOperation<User> = {
203
+ name: 'Bob',
204
+ luckyNumber: REMOVE_FIELD
205
+ };
206
+ ```
207
+
208
+ @category Utilities
209
+ */
210
+ type OptionalKeysOf<BaseType extends object> =
211
+ BaseType extends unknown // For distributing `BaseType`
212
+ ? (keyof {
213
+ [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never
214
+ }) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
215
+ : never; // Should never happen
216
+
217
+ /**
218
+ Extract all required keys from the given type.
219
+
220
+ This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
221
+
222
+ @example
223
+ ```
224
+ import type {RequiredKeysOf} from 'type-fest';
225
+
226
+ declare function createValidation<Entity extends object, Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>>(field: Key, validator: (value: Entity[Key]) => boolean): ValidatorFn;
227
+
228
+ interface User {
229
+ name: string;
230
+ surname: string;
231
+
232
+ luckyNumber?: number;
233
+ }
234
+
235
+ const validator1 = createValidation<User>('name', value => value.length < 25);
236
+ const validator2 = createValidation<User>('surname', value => value.length < 25);
237
+ ```
238
+
239
+ @category Utilities
240
+ */
241
+ type RequiredKeysOf<BaseType extends object> =
242
+ BaseType extends unknown // For distributing `BaseType`
243
+ ? Exclude<keyof BaseType, OptionalKeysOf<BaseType>>
244
+ : never; // Should never happen
245
+
253
246
  /**
254
247
  Omit any index signatures from the given object type, leaving only explicitly defined properties.
255
248
 
@@ -724,4 +717,5 @@ declare const toElementStream: <T>(stream: ReadableStream<string>) => ReadableSt
724
717
 
725
718
  declare const toPartialObjectStream: <T>(stream: ReadableStream<string>) => ReadableStream<PartialDeep<T>>;
726
719
 
727
- export { type StreamObjectOnFinishResult, type StreamObjectOptions, type StreamObjectResult, streamObject, toElementStream, toPartialObjectStream };
720
+ export { streamObject, toElementStream, toPartialObjectStream };
721
+ export type { StreamObjectOnFinishResult, StreamObjectOptions, StreamObjectResult };
package/dist/index.js CHANGED
@@ -21,7 +21,21 @@ function requireParse () {
21
21
  hasRequiredParse = 1;
22
22
  (function (exports) {
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.parse = void 0;
24
+ exports.parse = exports.enableErrorLogging = exports.disableErrorLogging = exports.setErrorLogger = void 0;
25
+ let logError = console.error;
26
+ function setErrorLogger(logger) {
27
+ logError = logger;
28
+ }
29
+ exports.setErrorLogger = setErrorLogger;
30
+ function disableErrorLogging() {
31
+ logError = () => {
32
+ };
33
+ }
34
+ exports.disableErrorLogging = disableErrorLogging;
35
+ function enableErrorLogging() {
36
+ logError = console.error;
37
+ }
38
+ exports.enableErrorLogging = enableErrorLogging;
25
39
  function parse(s) {
26
40
  if (s === void 0) {
27
41
  return void 0;
@@ -51,7 +65,7 @@ function requireParse () {
51
65
  exports.parse = parse;
52
66
  (function(parse2) {
53
67
  parse2.onExtraToken = (text, data, reminding) => {
54
- console.error("parsed json with extra tokens:", {
68
+ logError("parsed json with extra tokens:", {
55
69
  text,
56
70
  data,
57
71
  reminding
@@ -61,7 +75,7 @@ function requireParse () {
61
75
  function parseAny(s, e, fallback) {
62
76
  const parser = parsers[s[0]] || fallback;
63
77
  if (!parser) {
64
- console.error(`no parser registered for ${JSON.stringify(s[0])}:`, { s });
78
+ logError(`no parser registered for ${JSON.stringify(s[0])}:`, { s });
65
79
  throw e;
66
80
  }
67
81
  return parser(s, e);
@@ -232,7 +246,7 @@ function requireParse () {
232
246
  }
233
247
  {
234
248
  const prefix = JSON.stringify(s.slice(0, tokenStr.length));
235
- console.error(`unknown token starting with ${prefix}:`, { s });
249
+ logError(`unknown token starting with ${prefix}:`, { s });
236
250
  throw e;
237
251
  }
238
252
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xsai/stream-object",
3
3
  "type": "module",
4
- "version": "0.4.0-beta.5",
4
+ "version": "0.4.0-beta.6",
5
5
  "description": "extra-small AI SDK.",
6
6
  "author": "Moeru AI",
7
7
  "license": "MIT",
@@ -29,8 +29,8 @@
29
29
  "dist"
30
30
  ],
31
31
  "dependencies": {
32
- "@xsai/stream-text": "~0.4.0-beta.5",
33
- "xsschema": "~0.4.0-beta.5"
32
+ "@xsai/stream-text": "~0.4.0-beta.6",
33
+ "xsschema": "~0.4.0-beta.6"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@valibot/to-json-schema": "^1.0.0",