girgen 0.3.9 → 0.3.10

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 (2) hide show
  1. package/README.md +120 -86
  2. package/package.json +14 -4
package/README.md CHANGED
@@ -42,11 +42,11 @@ in `tsconfig.json`.
42
42
 
43
43
  ```json
44
44
  {
45
- "compilerOptions": {
46
- "lib": ["es2024"], // don't forget to specify a `lib` to avoid sourcing TypeScript's `dom` lib
47
- "skipLibCheck": true, // it's recommended to turn this on
48
- "typeRoots": [".types"]
49
- }
45
+ "compilerOptions": {
46
+ "lib": ["es2024"], // don't forget to specify a `lib` to avoid sourcing TypeScript's `dom` lib
47
+ "skipLibCheck": true, // it's recommended to turn this on
48
+ "typeRoots": [".types"]
49
+ }
50
50
  }
51
51
  ```
52
52
 
@@ -87,31 +87,31 @@ containing type declarations where each member is written in `kebab-case`:
87
87
 
88
88
  ```ts
89
89
  namespace MyClass {
90
- export interface SignalSignatures extends GObject.Object.SignalSignatures {
91
- // simple signal
92
- "my-signal"(arg: number): void
93
- // detailed signals are annotated with the `::{}` suffix
94
- "my-detailed-signal::{}"(arg: number): void
95
- }
96
-
97
- // ReadableProperties is also used for notify signal annotations
98
- export interface ReadableProperties
99
- extends GObject.Object.ReadableProperties {
100
- // property which has a public getter
101
- "my-prop": number
102
- }
103
-
104
- export interface WritableProperties
105
- extends GObject.Object.WritableProperties {
106
- // property which has a public setter
107
- "my-prop": number
108
- }
109
-
110
- export interface ConstructOnlyProperties
111
- extends GObject.Object.ConstructOnlyProperties {
112
- // property which can only be set at construction
113
- "my-ctor-prop": number
114
- }
90
+ export interface SignalSignatures extends GObject.Object.SignalSignatures {
91
+ // simple signal
92
+ "my-signal"(arg: number): void
93
+ // detailed signals are annotated with the `::{}` suffix
94
+ "my-detailed-signal::{}"(arg: number): void
95
+ }
96
+
97
+ // ReadableProperties is also used for notify signal annotations
98
+ export interface ReadableProperties
99
+ extends GObject.Object.ReadableProperties {
100
+ // property which has a public getter
101
+ "my-prop": number
102
+ }
103
+
104
+ export interface WritableProperties
105
+ extends GObject.Object.WritableProperties {
106
+ // property which has a public setter
107
+ "my-prop": number
108
+ }
109
+
110
+ export interface ConstructOnlyProperties
111
+ extends GObject.Object.ConstructOnlyProperties {
112
+ // property which can only be set at construction
113
+ "my-ctor-prop": number
114
+ }
115
115
  }
116
116
  ```
117
117
 
@@ -124,53 +124,53 @@ And the Class will refer to these using special `$` prefixed fields:
124
124
 
125
125
  ```ts
126
126
  class MyClass extends GObject.Object {
127
- declare readonly $signals: MyClass.SignalSignatures
128
- declare readonly $readableProperties: MyClass.ReadableProperties
129
- declare readonly $writableProperties: MyClass.WritableProperties
130
- declare readonly $constructOnlyProperties: MyClass.ConstructOnlyProperties
131
-
132
- static {
133
- GObject.registerClass(
134
- {
135
- Signals: {
136
- "my-signal": {
137
- param_types: [GObject.TYPE_DOUBLE],
138
- },
139
- "my-detailed-signal": {
140
- param_types: [GObject.TYPE_DOUBLE],
141
- flags: GObject.SignalFlags.DETAILED,
142
- },
143
- },
144
- Properties: {
145
- "my-prop": GObject.ParamSpec.double(
146
- "my-prop",
147
- null,
148
- null,
149
- GObject.ParamFlags.READWRITE,
150
- -GObject.Double.MAX_VALUE,
151
- GObject.Double.MAX_VALUE,
152
- ),
153
- "my-ctor-prop": GObject.ParamSpec.double(
154
- "my-ctor-prop",
155
- null,
156
- null,
157
- GObject.ParamFlags.CONSTRUCT_ONLY,
158
- -GObject.Double.MAX_VALUE,
159
- GObject.Double.MAX_VALUE,
160
- ),
161
- },
162
- },
163
- MyClass,
164
- )
165
- }
166
-
167
- // GObject.ConstructorProps can be used to infer props from the annotations
168
- constructor(props: Partial<GObject.ConstructorProps<MyClass>>) {
169
- super(props)
170
-
171
- // note that properties will be annotated as camelCase
172
- console.log(props.myProp, props.myCtorProp)
173
- }
127
+ declare readonly $signals: MyClass.SignalSignatures
128
+ declare readonly $readableProperties: MyClass.ReadableProperties
129
+ declare readonly $writableProperties: MyClass.WritableProperties
130
+ declare readonly $constructOnlyProperties: MyClass.ConstructOnlyProperties
131
+
132
+ static {
133
+ GObject.registerClass(
134
+ {
135
+ Signals: {
136
+ "my-signal": {
137
+ param_types: [GObject.TYPE_DOUBLE],
138
+ },
139
+ "my-detailed-signal": {
140
+ param_types: [GObject.TYPE_DOUBLE],
141
+ flags: GObject.SignalFlags.DETAILED,
142
+ },
143
+ },
144
+ Properties: {
145
+ "my-prop": GObject.ParamSpec.double(
146
+ "my-prop",
147
+ null,
148
+ null,
149
+ GObject.ParamFlags.READWRITE,
150
+ -GObject.Double.MAX_VALUE,
151
+ GObject.Double.MAX_VALUE,
152
+ ),
153
+ "my-ctor-prop": GObject.ParamSpec.double(
154
+ "my-ctor-prop",
155
+ null,
156
+ null,
157
+ GObject.ParamFlags.CONSTRUCT_ONLY,
158
+ -GObject.Double.MAX_VALUE,
159
+ GObject.Double.MAX_VALUE,
160
+ ),
161
+ },
162
+ },
163
+ MyClass,
164
+ )
165
+ }
166
+
167
+ // GObject.ConstructorProps can be used to infer props from the annotations
168
+ constructor(props: Partial<GObject.ConstructorProps<MyClass>>) {
169
+ super(props)
170
+
171
+ // note that properties will be annotated as camelCase
172
+ console.log(props.myProp, props.myCtorProp)
173
+ }
174
174
  }
175
175
  ```
176
176
 
@@ -181,15 +181,15 @@ annotations.
181
181
  const instance = new MyClass()
182
182
 
183
183
  instance.connect("my-signal", (source, arg) => {
184
- console.log(arg)
184
+ console.log(arg)
185
185
  })
186
186
 
187
187
  instance.connect("my-detailed-signal::detail", (source, arg) => {
188
- console.log(arg)
188
+ console.log(arg)
189
189
  })
190
190
 
191
191
  instance.connect("notify::my-prop", (_, pspec) => {
192
- console.log(pspec.name)
192
+ console.log(pspec.name)
193
193
  })
194
194
  ```
195
195
 
@@ -198,13 +198,47 @@ typecast to correctly infer types within the class.
198
198
 
199
199
  ```ts
200
200
  class MyClass {
201
- myFn(this: MyClass) {
202
- this.emit("my-signal", 0)
203
- }
201
+ myFn(this: MyClass) {
202
+ this.emit("my-signal", 0)
203
+ }
204
+
205
+ myFn() {
206
+ const self = this as MyClass
207
+ self.emit("my-signal", 0)
208
+ }
209
+ }
210
+ ```
204
211
 
205
- myFn() {
206
- const self = this as MyClass
207
- self.emit("my-signal", 0)
212
+ ### Module Augmentation
213
+
214
+ If you are using
215
+ [`Gio._promisify`](https://gjs.guide/guides/gjs/asynchronous-programming.html#promisify-helper)
216
+ you can augment namespaces.
217
+
218
+ ```ts
219
+ import Gio from "gi://Gio?version=2.0"
220
+ import GLib from "gi://GLib?version=2.0"
221
+
222
+ Gio._promisify(
223
+ Gio.InputStream.prototype,
224
+ "read_bytes_async",
225
+ "read_bytes_finish",
226
+ )
227
+
228
+ declare module "gi://Gio?version=2.0" {
229
+ namespace GI {
230
+ namespace Gio {
231
+ interface InputStream {
232
+ read_bytes_async(
233
+ count: number,
234
+ io_priority: number,
235
+ cancellable: Gio.Cancellable | null,
236
+ ): GLib.Bytes
237
+ }
208
238
  }
239
+ }
209
240
  }
241
+
242
+ declare const stream: Gio.InputStream
243
+ const bytes = await stream.read_bytes_async(4096, GLib.PRIORITY_DEFAULT, null)
210
244
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "girgen",
3
- "version": "0.3.9",
3
+ "version": "0.3.10",
4
4
  "author": "Aylur",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -17,14 +17,24 @@
17
17
  "prettier": {
18
18
  "semi": false,
19
19
  "tabWidth": 4,
20
- "printWidth": 80
20
+ "printWidth": 80,
21
+ "overrides": [
22
+ {
23
+ "files": "**/*.md",
24
+ "options": {
25
+ "tabWidth": 2,
26
+ "printWidth": 80,
27
+ "proseWrap": "always"
28
+ }
29
+ }
30
+ ]
21
31
  },
22
32
  "devDependencies": {
23
33
  "@types/node": "latest"
24
34
  },
25
35
  "optionalDependencies": {
26
- "@girgen/linux-x64": "0.3.9",
27
- "@girgen/linux-arm64": "0.3.9"
36
+ "@girgen/linux-x64": "0.3.10",
37
+ "@girgen/linux-arm64": "0.3.10"
28
38
  },
29
39
  "files": [
30
40
  "bin"