@girs/gfls-1 4.2.0 → 4.3.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 (3) hide show
  1. package/README.md +8 -8
  2. package/gfls-1.d.ts +229 -82
  3. package/package.json +15 -15
package/README.md CHANGED
@@ -5,25 +5,25 @@
5
5
  ![downloads/week](https://img.shields.io/npm/dw/@girs/gfls-1)
6
6
 
7
7
 
8
- GJS TypeScript type definitions for Gfls-1 using [ts-for-gir](https://github.com/gjsify/ts-for-gir) v4.2.0.
8
+ GJS TypeScript type definitions for Gfls-1 using [ts-for-gir](https://github.com/gjsify/ts-for-gir) v4.3.0.
9
9
 
10
10
  ## Install
11
11
 
12
- To use this type definitions, install them with NPM:
12
+ Install the type definitions with npm:
13
13
  ```bash
14
14
  npm install @girs/gfls-1
15
15
  ```
16
16
 
17
17
  ## Usage
18
18
 
19
- You can import this package into your project like this:
19
+ Import it like any other module:
20
20
  ```ts
21
21
  import Gfls from '@girs/gfls-1';
22
22
  ```
23
23
 
24
24
  ### Ambient Modules
25
25
 
26
- You can also use [ambient modules](https://github.com/gjsify/ts-for-gir/tree/main/packages/cli#ambient-modules) to import this module like you would do this in JavaScript.
26
+ [Ambient modules](https://github.com/gjsify/ts-for-gir/tree/main/packages/cli#ambient-modules) let you write the same import you would in plain JavaScript.
27
27
  For this you need to include `@girs/gfls-1` or `@girs/gfls-1/ambient` in your `tsconfig` or entry point Typescript file:
28
28
 
29
29
  `index.ts`:
@@ -42,7 +42,7 @@ import '@girs/gfls-1'
42
42
  }
43
43
  ```
44
44
 
45
- Now you can import the ambient module with TypeScript support:
45
+ The ambient module now resolves with types:
46
46
 
47
47
  ```ts
48
48
  import Gfls from 'gi://Gfls?version=1';
@@ -50,7 +50,7 @@ import Gfls from 'gi://Gfls?version=1';
50
50
 
51
51
  ### Global import
52
52
 
53
- You can also import the module with Typescript support using the global `imports.gi` object of GJS.
53
+ GJS's global `imports.gi` works too, with types.
54
54
  For this you need to include `@girs/gfls-1` or `@girs/gfls-1/import` in your `tsconfig` or entry point Typescript file:
55
55
 
56
56
  `index.ts`:
@@ -69,7 +69,7 @@ import '@girs/gfls-1'
69
69
  }
70
70
  ```
71
71
 
72
- Now you have also type support for this, too:
72
+ That form carries types as well:
73
73
 
74
74
  ```ts
75
75
  const Gfls = imports.gi.Gfls;
@@ -77,7 +77,7 @@ const Gfls = imports.gi.Gfls;
77
77
 
78
78
  ### Bundle
79
79
 
80
- Depending on your project configuration, it is recommended to use a bundler like [esbuild](https://esbuild.github.io/). You can find examples using different bundlers [here](https://github.com/gjsify/ts-for-gir/tree/main/examples).
80
+ Most projects want a bundler. [esbuild](https://esbuild.github.io/) is the smallest thing that works; the [examples directory](https://github.com/gjsify/ts-for-gir/tree/main/examples) has setups for several others.
81
81
 
82
82
  ## Other packages
83
83
 
package/gfls-1.d.ts CHANGED
@@ -32,6 +32,53 @@ export namespace Gfls {
32
32
  */
33
33
 
34
34
 
35
+ /**
36
+ * @gir-type Enum
37
+ */
38
+ export namespace IconvResult {
39
+ export const $gtype: GObject.GType<IconvResult>;
40
+ }
41
+
42
+ /**
43
+ * Used as the result value of `gfls_iconv_feed()`.
44
+ * @gir-type Enum
45
+ * @since 0.4
46
+ */
47
+ enum IconvResult {
48
+ /**
49
+ * Everything OK.
50
+ */
51
+ OK,
52
+ /**
53
+ * An error occurred.
54
+ */
55
+ ERROR,
56
+ /**
57
+ * Stopped at an invalid character in
58
+ * the `inbuf`; or the character could not be represented in the target
59
+ * character set. `*inbuf` is left pointing to the beginning of the invalid or
60
+ * unconvertible sequence.
61
+ */
62
+ ILLEGAL_SEQUENCE,
63
+ /**
64
+ * The input byte sequence ends with
65
+ * an incomplete multi-byte character. `*inbuf` is left pointing to the
66
+ * beginning of the incomplete multi-byte character.
67
+ */
68
+ INCOMPLETE_INPUT,
69
+ /**
70
+ * The output buffer has no more
71
+ * room for the next converted character.
72
+ */
73
+ OUTPUT_BUFFER_FULL,
74
+ /**
75
+ * A number of nonreversible
76
+ * conversions have been performed.
77
+ */
78
+ LOSSY_CONVERSION,
79
+ }
80
+
81
+
35
82
  /**
36
83
  * An error code used with the `GFLS_LOADER_ERROR` domain.
37
84
  * @gir-type Struct
@@ -65,106 +112,72 @@ export namespace Gfls {
65
112
 
66
113
 
67
114
  /**
68
- * Free the resources allocated by Gfls. For example it unrefs the singleton
69
- * objects.
115
+ * This function converts `input_bytes` from a codeset to another.
70
116
  *
71
- * It is not mandatory to call this function, it's just to be friendlier to
72
- * memory debugging tools. This function is meant to be called at the end of
73
- * `main()`. It can be called several times.
74
- * @since 0.1
75
- */
76
- function finalize(): void;
77
-
78
- /**
79
- * Initializes the Gfls library (e.g. for the internationalization).
117
+ * `from_codeset` and `to_codeset` must be compatible with iconv, see
118
+ * `gfls_iconv_open()`.
80
119
  *
81
- * This function can be called several times, but is meant to be called at the
82
- * beginning of `main()`, before any other Gfls function call.
83
- * @since 0.1
84
- */
85
- function init(): void;
86
-
87
- /**
88
- * This function starts a read operation on `input_stream`. It is meant to be
89
- * used as the only read operation on `input_stream`, to get a {@link GLib.Bytes} as a
90
- * result, with `max_size` as the provided maximum number of bytes to read.
120
+ * Note that `from_codeset` and `to_codeset` can be equal. It is useful to
121
+ * identify the valid characters from the invalid ones.
91
122
  *
92
- * `expected_size` is typically a {@link Gio.File} size as returned by
93
- * `g_file_info_get_size()`. But note that in that case, the returned {@link GLib.Bytes} may
94
- * contain a different number of bytes than what was expected (the
95
- * TOC/TOU problem: time of check to time of use). `expected_size` is used as an
96
- * indication to how much memory to allocate initially.
123
+ * The output is the combination of `output_bytes` and
124
+ * `output_bytes_valid_region`. Output bytes that are part of
125
+ * `output_bytes_valid_region` are the valid characters (successfully converted).
126
+ * The other output bytes are invalid characters (copied as is from
127
+ * `input_bytes`).
97
128
  *
98
- * See the {@link Gio.AsyncResult} documentation to know how to use this function.
99
- * @param input_stream a {@link Gio.InputStream}.
100
- * @param expected_size the expected number of bytes contained in `input_stream`.
101
- * @param max_size the maximum number of bytes to read.
102
- * @param io_priority the I/O priority of the request. E.g. `G_PRIORITY_LOW`, `G_PRIORITY_DEFAULT` or `G_PRIORITY_HIGH`.
103
- * @param cancellable optional {@link Gio.Cancellable} object, `null` to ignore.
104
- * @since 0.1
129
+ * If `allow_invalid_characters` is `false`:
130
+ * - As soon as an invalid character is encountered, `false` is returned by this
131
+ * function and `output_bytes` and `output_bytes_valid_region` will return
132
+ * `null`.
133
+ * - Otherwise, if everything goes well, `true` is returned alongside the
134
+ * `output_bytes` and `output_bytes_valid_region` (the latter contains in this
135
+ * case only one, valid sub-region).
136
+ * @param input_bytes the input {@link GLib.Bytes} to convert.
137
+ * @param to_codeset destination codeset.
138
+ * @param from_codeset source codeset.
139
+ * @param allow_invalid_characters whether invalid characters are allowed.
140
+ * @returns `true` on success, `false` otherwise.
141
+ * @since 0.4
105
142
  */
106
- function input_stream_read_async(input_stream: Gio.InputStream, expected_size: bigint | number, max_size: bigint | number, io_priority: number, cancellable: Gio.Cancellable | null): globalThis.Promise<GLib.Bytes>;
143
+ function encoding_convert(input_bytes: GLib.Bytes | Uint8Array, to_codeset: string, from_codeset: string, allow_invalid_characters: boolean): [boolean, GLib.Bytes, BytesRegion];
144
+
107
145
  /**
108
- * This function starts a read operation on `input_stream`. It is meant to be
109
- * used as the only read operation on `input_stream`, to get a {@link GLib.Bytes} as a
110
- * result, with `max_size` as the provided maximum number of bytes to read.
146
+ * Tries a conversion on `input_bytes`, discarding the output.
111
147
  *
112
- * `expected_size` is typically a {@link Gio.File} size as returned by
113
- * `g_file_info_get_size()`. But note that in that case, the returned {@link GLib.Bytes} may
114
- * contain a different number of bytes than what was expected (the
115
- * TOC/TOU problem: time of check to time of use). `expected_size` is used as an
116
- * indication to how much memory to allocate initially.
148
+ * `from_codeset` and `to_codeset` must be compatible with iconv, see
149
+ * `gfls_iconv_open()`.
117
150
  *
118
- * See the {@link Gio.AsyncResult} documentation to know how to use this function.
119
- * @param input_stream a {@link Gio.InputStream}.
120
- * @param expected_size the expected number of bytes contained in `input_stream`.
121
- * @param max_size the maximum number of bytes to read.
122
- * @param io_priority the I/O priority of the request. E.g. `G_PRIORITY_LOW`, `G_PRIORITY_DEFAULT` or `G_PRIORITY_HIGH`.
123
- * @param cancellable optional {@link Gio.Cancellable} object, `null` to ignore.
124
- * @param callback a {@link Gio.AsyncReadyCallback} to call when the operation is finished.
125
- * @since 0.1
151
+ * If `input_bytes` ends with an incomplete multi-byte character, that part is
152
+ * ignored. So `input_bytes` can be for example the first chunk of a file when
153
+ * loading it.
154
+ * @param input_bytes a {@link GLib.Bytes}.
155
+ * @param to_codeset destination codeset.
156
+ * @param from_codeset source codeset.
157
+ * @returns `true` if and only if `input_bytes` can be converted without errors, without invalid characters and without fallback characters.
158
+ * @since 0.4
126
159
  */
127
- function input_stream_read_async(input_stream: Gio.InputStream, expected_size: bigint | number, max_size: bigint | number, io_priority: number, cancellable: Gio.Cancellable | null, callback: Gio.AsyncReadyCallback<Gio.InputStream> | null): void;
160
+ function encoding_try_convert(input_bytes: GLib.Bytes | Uint8Array, to_codeset: string, from_codeset: string): boolean;
161
+
128
162
  /**
129
- * This function starts a read operation on `input_stream`. It is meant to be
130
- * used as the only read operation on `input_stream`, to get a {@link GLib.Bytes} as a
131
- * result, with `max_size` as the provided maximum number of bytes to read.
132
- *
133
- * `expected_size` is typically a {@link Gio.File} size as returned by
134
- * `g_file_info_get_size()`. But note that in that case, the returned {@link GLib.Bytes} may
135
- * contain a different number of bytes than what was expected (the
136
- * TOC/TOU problem: time of check to time of use). `expected_size` is used as an
137
- * indication to how much memory to allocate initially.
163
+ * Free the resources allocated by Gfls. For example it unrefs the singleton
164
+ * objects.
138
165
  *
139
- * See the {@link Gio.AsyncResult} documentation to know how to use this function.
140
- * @param input_stream a {@link Gio.InputStream}.
141
- * @param expected_size the expected number of bytes contained in `input_stream`.
142
- * @param max_size the maximum number of bytes to read.
143
- * @param io_priority the I/O priority of the request. E.g. `G_PRIORITY_LOW`, `G_PRIORITY_DEFAULT` or `G_PRIORITY_HIGH`.
144
- * @param cancellable optional {@link Gio.Cancellable} object, `null` to ignore.
145
- * @param callback a {@link Gio.AsyncReadyCallback} to call when the operation is finished.
166
+ * It is not mandatory to call this function, it's just to be friendlier to
167
+ * memory debugging tools. This function is meant to be called at the end of
168
+ * `main()`. It can be called several times.
146
169
  * @since 0.1
147
170
  */
148
- function input_stream_read_async(input_stream: Gio.InputStream, expected_size: bigint | number, max_size: bigint | number, io_priority: number, cancellable: Gio.Cancellable | null, callback: Gio.AsyncReadyCallback<Gio.InputStream> | null): globalThis.Promise<GLib.Bytes> | void;
171
+ function finalize(): void;
149
172
 
150
173
  /**
151
- * Finishes an operation started with `gfls_input_stream_read_async()`.
152
- *
153
- * If `is_truncated` is set to `true`, it is not an error (`error` is not set), and
154
- * a {@link GLib.Bytes} is returned. However, since `gfls_input_stream_read_async()` is meant
155
- * to be used as the only read operation on `input_stream`, it is an undefined
156
- * behavior if you try to read more content from `input_stream`.
174
+ * Initializes the Gfls library (e.g. for the internationalization).
157
175
  *
158
- * The data contained in the resulting {@link GLib.Bytes} is always zero-terminated, but
159
- * this is not included in the {@link GLib.Bytes} length. The resulting {@link GLib.Bytes} should be
160
- * freed with `g_bytes_unref()` when no longer in use.
161
- * @param input_stream a {@link Gio.InputStream}.
162
- * @param result a {@link Gio.AsyncResult}.
163
- * @param is_truncated will be set to `true` if the `input_stream` contains more data to be read, but the maximum number of bytes to read has been reached.
164
- * @returns a {@link GLib.Bytes}, or `null` on error.
176
+ * This function can be called several times, but is meant to be called at the
177
+ * beginning of `main()`, before any other Gfls function call.
165
178
  * @since 0.1
166
179
  */
167
- function input_stream_read_finish(input_stream: Gio.InputStream, result: Gio.AsyncResult, is_truncated: boolean): GLib.Bytes;
180
+ function init(): void;
168
181
 
169
182
  /**
170
183
  * Starts a basic file loading operation.
@@ -250,6 +263,13 @@ export namespace Gfls {
250
263
  */
251
264
  function utf8_find_very_long_line(str: string, max_n_bytes_per_line: number): string;
252
265
 
266
+ /**
267
+ * @gir-type Callback
268
+ */
269
+ interface SimpleProgressCallback {
270
+ (number: number): void;
271
+ }
272
+
253
273
  /**
254
274
  * @gir-type Callback
255
275
  */
@@ -463,6 +483,133 @@ export namespace Gfls {
463
483
  }
464
484
 
465
485
 
486
+ /**
487
+ * @gir-type Struct
488
+ */
489
+ abstract class BytesRegion {
490
+ static $gtype: GObject.GType<BytesRegion>;
491
+
492
+ // Methods
493
+ /**
494
+ * Frees `region`.
495
+ */
496
+ free(): void;
497
+
498
+ /**
499
+ * Frees `iter`.
500
+ * @param iter a {@link Gfls.BytesRegionIter}.
501
+ */
502
+ iter_free(iter: BytesRegionIter | null): void;
503
+
504
+ /**
505
+ * Gets the sub-region at this iterator.
506
+ *
507
+ * `sub_region_size` and `offset` can be used as arguments to
508
+ * `g_bytes_get_region()`.
509
+ *
510
+ * `is_part_of_region` has the same meaning as for
511
+ * `gfls_bytes_region_builder_append()`. {@link Gfls.BytesRegionIter} iterates on both the
512
+ * region and the holes, so that the corresponding {@link GLib.Bytes} is traversed from
513
+ * start to end.
514
+ * @param iter a {@link Gfls.BytesRegionIter}. It must not be the end iterator.
515
+ */
516
+ iter_get_sub_region(iter: BytesRegionIter): [number, number, boolean];
517
+
518
+ /**
519
+ * @param iter a {@link Gfls.BytesRegionIter}.
520
+ * @returns whether `iter` is the end iterator.
521
+ */
522
+ iter_is_end(iter: BytesRegionIter): boolean;
523
+
524
+ /**
525
+ * Moves `iter` to the next sub-region.
526
+ *
527
+ * If all sub-regions have been traversed, `iter` is set to the end iterator.
528
+ * @param iter a {@link Gfls.BytesRegionIter}. The end iterator is accepted as an input value.
529
+ */
530
+ iter_next(iter: BytesRegionIter): void;
531
+
532
+ /**
533
+ * @param bytes a {@link GLib.Bytes}.
534
+ * @returns whether `region` can be applied to `bytes` (it checks the total size).
535
+ */
536
+ match_bytes(bytes: GLib.Bytes | Uint8Array): boolean;
537
+
538
+ /**
539
+ * The format is:
540
+ *
541
+ * `[offset, sub_region_size, is_part_of_region]\n`
542
+ *
543
+ * One line per sub-region, in order.
544
+ * @returns a string representation of `region`.
545
+ */
546
+ to_string(): string;
547
+ }
548
+
549
+
550
+ /**
551
+ * @gir-type Struct
552
+ */
553
+ abstract class BytesRegionBuilder {
554
+ static $gtype: GObject.GType<BytesRegionBuilder>;
555
+
556
+ // Methods
557
+ /**
558
+ * Appends a sub-region at the end.
559
+ *
560
+ * If `is_part_of_region` is `false` it creates a hole.
561
+ *
562
+ * Contiguous sub-regions of the same kind are merged and will thus be treated
563
+ * as a single sub-region. So you can conveniently call this function several
564
+ * times in a row with the same value for `is_part_of_region`.
565
+ *
566
+ * In order to create a {@link Gfls.BytesRegion} that will traverse a whole {@link GLib.Bytes}, it
567
+ * is required to call this function the right amount of times, even if it ends
568
+ * with a hole. See also `gfls_bytes_region_match_bytes()`.
569
+ * @param sub_region_length the length of the sub-region. Must not be equal to 0.
570
+ * @param is_part_of_region whether the sub-region is part of the region.
571
+ */
572
+ append(sub_region_length: bigint | number, is_part_of_region: boolean): void;
573
+
574
+ /**
575
+ * Creates a {@link Gfls.BytesRegion} and frees `builder`.
576
+ * @param free_data if `true`, the data is freed as well.
577
+ * @returns a {@link Gfls.BytesRegion}, or `null` if `free_data` is `true`.
578
+ */
579
+ free(free_data: boolean): BytesRegion | null;
580
+
581
+ /**
582
+ * @returns the current total size, in number of bytes (holes included).
583
+ */
584
+ get_current_size(): number;
585
+ }
586
+
587
+
588
+ /**
589
+ * @gir-type Struct
590
+ */
591
+ abstract class BytesRegionIter {
592
+ static $gtype: GObject.GType<BytesRegionIter>;
593
+ }
594
+
595
+
596
+ /**
597
+ * @gir-type Struct
598
+ */
599
+ abstract class Iconv {
600
+ static $gtype: GObject.GType<Iconv>;
601
+
602
+ // Methods
603
+ /**
604
+ * Closes and frees `conv`.
605
+ *
606
+ * If you need to know if closing `conv` returns an error, call
607
+ * `gfls_iconv_close()` explicitly beforehand.
608
+ */
609
+ free(): void;
610
+ }
611
+
612
+
466
613
  /**
467
614
  * @gir-type Alias
468
615
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@girs/gfls-1",
3
- "version": "4.2.0",
3
+ "version": "4.3.0",
4
4
  "description": "GJS TypeScript type definitions for Gfls-1",
5
5
  "type": "module",
6
6
  "module": "gfls-1.js",
@@ -31,20 +31,20 @@
31
31
  "test": "tsc --project tsconfig.json"
32
32
  },
33
33
  "dependencies": {
34
- "@girs/gjs": "^4.2.0",
35
- "@girs/gtk-3.0": "^4.2.0",
36
- "@girs/xlib-2.0": "^4.2.0",
37
- "@girs/gdk-3.0": "^4.2.0",
38
- "@girs/cairo-1.0": "^4.2.0",
39
- "@girs/gobject-2.0": "^4.2.0",
40
- "@girs/glib-2.0": "^4.2.0",
41
- "@girs/pango-1.0": "^4.2.0",
42
- "@girs/harfbuzz-0.0": "^4.2.0",
43
- "@girs/freetype2-2.0": "^4.2.0",
44
- "@girs/gio-2.0": "^4.2.0",
45
- "@girs/gmodule-2.0": "^4.2.0",
46
- "@girs/gdkpixbuf-2.0": "^4.2.0",
47
- "@girs/atk-1.0": "^4.2.0" },
34
+ "@girs/gjs": "^4.3.0",
35
+ "@girs/gtk-3.0": "^4.3.0",
36
+ "@girs/xlib-2.0": "^4.3.0",
37
+ "@girs/gdk-3.0": "^4.3.0",
38
+ "@girs/cairo-1.0": "^4.3.0",
39
+ "@girs/gobject-2.0": "^4.3.0",
40
+ "@girs/glib-2.0": "^4.3.0",
41
+ "@girs/pango-1.0": "^4.3.0",
42
+ "@girs/harfbuzz-0.0": "^4.3.0",
43
+ "@girs/freetype2-2.0": "^4.3.0",
44
+ "@girs/gio-2.0": "^4.3.0",
45
+ "@girs/gmodule-2.0": "^4.3.0",
46
+ "@girs/gdkpixbuf-2.0": "^4.3.0",
47
+ "@girs/atk-1.0": "^4.3.0" },
48
48
  "devDependencies": {
49
49
  "typescript": "*"
50
50
  },