typed-factorio 1.7.2 → 1.7.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,153 @@
1
+ import {ChildProcess} from 'child_process';
2
+
3
+ declare namespace open {
4
+ interface Options {
5
+ /**
6
+ Wait for the opened app to exit before fulfilling the promise. If `false` it's fulfilled immediately when opening the app.
7
+
8
+ Note that it waits for the app to exit, not just for the window to close.
9
+
10
+ On Windows, you have to explicitly specify an app for it to be able to wait.
11
+
12
+ @default false
13
+ */
14
+ readonly wait?: boolean;
15
+
16
+ /**
17
+ __macOS only__
18
+
19
+ Do not bring the app to the foreground.
20
+
21
+ @default false
22
+ */
23
+ readonly background?: boolean;
24
+
25
+ /**
26
+ __macOS only__
27
+
28
+ Open a new instance of the app even it's already running.
29
+
30
+ A new instance is always opened on other platforms.
31
+
32
+ @default false
33
+ */
34
+ readonly newInstance?: boolean;
35
+
36
+ /**
37
+ Specify the `name` of the app to open the `target` with, and optionally, app `arguments`. `app` can be an array of apps to try to open and `name` can be an array of app names to try. If each app fails, the last error will be thrown.
38
+
39
+ The app name is platform dependent. Don't hard code it in reusable modules. For example, Chrome is `google chrome` on macOS, `google-chrome` on Linux and `chrome` on Windows. If possible, use [`open.apps`](#openapps) which auto-detects the correct binary to use.
40
+
41
+ You may also pass in the app's full path. For example on WSL, this can be `/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe` for the Windows installation of Chrome.
42
+
43
+ The app `arguments` are app dependent. Check the app's documentation for what arguments it accepts.
44
+ */
45
+ readonly app?: App | readonly App[];
46
+
47
+ /**
48
+ Allow the opened app to exit with nonzero exit code when the `wait` option is `true`.
49
+
50
+ We do not recommend setting this option. The convention for success is exit code zero.
51
+
52
+ @default false
53
+ */
54
+ readonly allowNonzeroExitCode?: boolean;
55
+ }
56
+
57
+ interface OpenAppOptions extends Omit<Options, 'app'> {
58
+ /**
59
+ Arguments passed to the app.
60
+
61
+ These arguments are app dependent. Check the app's documentation for what arguments it accepts.
62
+ */
63
+ readonly arguments?: readonly string[];
64
+ }
65
+
66
+ type AppName =
67
+ | 'chrome'
68
+ | 'firefox'
69
+ | 'edge';
70
+
71
+ type App = {
72
+ name: string | readonly string[];
73
+ arguments?: readonly string[];
74
+ };
75
+ }
76
+
77
+ // eslint-disable-next-line no-redeclare
78
+ declare const open: {
79
+ /**
80
+ Open stuff like URLs, files, executables. Cross-platform.
81
+
82
+ Uses the command `open` on macOS, `start` on Windows and `xdg-open` on other platforms.
83
+
84
+ There is a caveat for [double-quotes on Windows](https://github.com/sindresorhus/open#double-quotes-on-windows) where all double-quotes are stripped from the `target`.
85
+
86
+ @param target - The thing you want to open. Can be a URL, file, or executable. Opens in the default app for the file type. For example, URLs open in your default browser.
87
+ @returns The [spawned child process](https://nodejs.org/api/child_process.html#child_process_class_childprocess). You would normally not need to use this for anything, but it can be useful if you'd like to attach custom event listeners or perform other operations directly on the spawned process.
88
+
89
+ @example
90
+ ```
91
+ import open = require('open');
92
+
93
+ // Opens the image in the default image viewer
94
+ await open('unicorn.png', {wait: true});
95
+ console.log('The image viewer app closed');
96
+
97
+ // Opens the url in the default browser
98
+ await open('https://sindresorhus.com');
99
+
100
+ // Opens the URL in a specified browser.
101
+ await open('https://sindresorhus.com', {app: {name: 'firefox'}});
102
+
103
+ // Specify app arguments.
104
+ await open('https://sindresorhus.com', {app: {name: 'google chrome', arguments: ['--incognito']}});
105
+ ```
106
+ */
107
+ (
108
+ target: string,
109
+ options?: open.Options
110
+ ): Promise<ChildProcess>;
111
+
112
+ /**
113
+ An object containing auto-detected binary names for common apps. Useful to work around cross-platform differences.
114
+
115
+ @example
116
+ ```
117
+ import open = require('open');
118
+
119
+ await open('https://google.com', {
120
+ app: {
121
+ name: open.apps.chrome
122
+ }
123
+ });
124
+ ```
125
+ */
126
+ apps: Record<open.AppName, string | readonly string[]>;
127
+
128
+ /**
129
+ Open an app. Cross-platform.
130
+
131
+ Uses the command `open` on macOS, `start` on Windows and `xdg-open` on other platforms.
132
+
133
+ @param name - The app you want to open. Can be either builtin supported `open.apps` names or other name supported in platform.
134
+ @returns The [spawned child process](https://nodejs.org/api/child_process.html#child_process_class_childprocess). You would normally not need to use this for anything, but it can be useful if you'd like to attach custom event listeners or perform other operations directly on the spawned process.
135
+
136
+ @example
137
+ ```
138
+ const {apps, openApp} = require('open');
139
+
140
+ // Open Firefox
141
+ await openApp(apps.firefox);
142
+
143
+ // Open Chrome incognito mode
144
+ await openApp(apps.chrome, {arguments: ['--incognito']});
145
+
146
+ // Open Xcode
147
+ await openApp('xcode');
148
+ ```
149
+ */
150
+ openApp: (name: open.App['name'], options?: open.OpenAppOptions) => Promise<ChildProcess>;
151
+ };
152
+
153
+ export = open;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typed-factorio",
3
- "version": "1.7.2",
3
+ "version": "1.7.3",
4
4
  "description": "Featureful typescript definitions for the the Factorio modding lua api.",
5
5
  "keywords": [
6
6
  "factorio",
@@ -15,46 +15,46 @@
15
15
  "*.d.ts",
16
16
  "!generator/**/*"
17
17
  ],
18
+ "type": "module",
18
19
  "homepage": "https://github.com/GlassBricks/typed-factorio#readme",
19
20
  "scripts": {
20
- "generate": "ts-node -P generator/tsconfig.json generator/main.ts",
21
+ "generate": "ts-node --esm -P generator/tsconfig.json generator/main.ts",
21
22
  "clean": "rimraf generated",
22
- "pretest": "yarn run generate",
23
23
  "test": "jest",
24
24
  "lint": "eslint .",
25
- "check": "yarn run lint && yarn run test",
25
+ "check": "yarn run lint && yarn run generate && yarn run test",
26
26
  "prepublishOnly": "yarn run check",
27
- "download-latest-runtime-api": "ts-node ./scripts/download-latest.ts",
28
- "new-version-changelog": "ts-node ./scripts/new-version-changelog.ts",
27
+ "download-latest-runtime-api": "ts-node --esm ./scripts/download-latest.ts",
28
+ "new-version-changelog": "ts-node --esm ./scripts/new-version-changelog.ts",
29
29
  "next-version": "yarn run download-latest-runtime-api && yarn run clean && yarn run check && yarn run new-version-changelog && git add . && yarn version --minor"
30
30
  },
31
31
  "peerDependencies": {
32
- "lua-types": "^2.12.2",
32
+ "lua-types": "^2.13.0",
33
33
  "typescript-to-lua": "^1.6.1"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/jest": "^28.1.8",
37
- "@types/node": "^18.7.14",
37
+ "@types/node": "^18.7.15",
38
38
  "@types/prettier": "^2.7.0",
39
- "@typescript-eslint/eslint-plugin": "^5.36.1",
40
- "@typescript-eslint/parser": "^5.36.1",
41
- "chalk": "^4.1.2",
42
- "eslint": "~8.22.0",
39
+ "@typescript-eslint/eslint-plugin": "^5.36.2",
40
+ "@typescript-eslint/parser": "^5.36.2",
41
+ "chalk": "^5.0.1",
42
+ "eslint": "~8.23.0",
43
43
  "eslint-config-prettier": "^8.5.0",
44
44
  "eslint-config-standard": "^17.0.0",
45
- "eslint-import-resolver-typescript": "^3.5.0",
45
+ "eslint-import-resolver-typescript": "^3.5.1",
46
46
  "eslint-plugin-import": "^2.26.0",
47
47
  "eslint-plugin-n": "^15.2.5",
48
48
  "eslint-plugin-node": "^11.1.0",
49
49
  "eslint-plugin-prettier": "^4.2.1",
50
50
  "eslint-plugin-promise": "^6.0.1",
51
51
  "jest": "^28.1.3",
52
- "lua-types": "^2.12.2",
52
+ "lua-types": "^2.13.0",
53
53
  "prettier": "^2.7.1",
54
54
  "ts-jest": "^28.0.8",
55
55
  "ts-node": "^10.9.1",
56
- "typescript": "~4.7.4",
57
- "typescript-to-lua": "^1.9.0"
56
+ "typescript": "~4.8.2",
57
+ "typescript-to-lua": "^1.10.0"
58
58
  },
59
59
  "packageManager": "yarn@3.2.3"
60
- }
60
+ }
package/runtime/util.d.ts CHANGED
@@ -8,54 +8,58 @@ declare module "util" {
8
8
  namespace table {
9
9
  function deepcopy<T>(table: T): T
10
10
 
11
- function compare<T>(tb1: T, tb2: T): boolean
11
+ function compare<T extends table>(tb1: T, tb2: T): boolean
12
12
  }
13
13
 
14
14
  function copy<T>(table: T): T
15
15
 
16
- function distance(position1: MapPosition, position2: MapPosition): number
16
+ function distance(position1: MapPosition | MapPositionArray, position2: MapPosition | MapPositionArray): number
17
17
 
18
- function positiontostr(position: MapPosition): string
18
+ function positiontostr(position: MapPosition | MapPositionArray): string
19
19
 
20
20
  function formattime(ticks: number): string
21
21
 
22
22
  /** Supports 'rrggbb', 'rgb', 'rrggbbaa', 'rgba', 'ww', 'w' */
23
- function color(hex: string): ColorTable
23
+ function color(hex: string): Color
24
24
 
25
- function premul_color(color: Color): ColorTable
25
+ function premul_color(color: Color): Color
26
26
 
27
27
  function mix_color(c1: Color, c2: Color): ColorArray
28
28
 
29
29
  function multiply_color(c1: Color, n: number): ColorArray
30
30
 
31
31
  function moveposition(
32
- position: MapPosition,
32
+ position: MapPositionArray,
33
33
  direction: defines.direction.north | defines.direction.east | defines.direction.south | defines.direction.west,
34
34
  distance: number
35
- ): MapPosition
36
- function moveposition(position: MapPosition, direction: defines.direction, distance: number): MapPosition | undefined
35
+ ): MapPositionArray
36
+ function moveposition(
37
+ position: MapPositionArray,
38
+ direction: defines.direction,
39
+ distance: number
40
+ ): MapPositionArray | nil
37
41
 
38
42
  function oppositedirection(direction: defines.direction): defines.direction
39
43
 
40
44
  /** Creates a new array where each element in `stripes` is duplicated `count` times */
41
- function multiplystripes<T>(count: number, stripes: T[]): T[]
45
+ function multiplystripes<T>(count: number, stripes: readonly T[]): T[]
42
46
 
43
47
  /** Gets tile position by pixel */
44
- function by_pixel(x: number, y: number): MapPosition
48
+ function by_pixel(x: number, y: number): MapPositionArray
45
49
 
46
50
  /** Gets tile position by pixel, hr */
47
- function by_pixel_hr(x: number, y: number): MapPosition
51
+ function by_pixel_hr(x: number, y: number): MapPositionArray
48
52
 
49
53
  // omitted: foreach_sprite_definition
50
54
 
51
- function add_shift(a: MapPositionArray | undefined, b: MapPositionArray): MapPositionArray
52
- function add_shift(a: MapPositionArray, b: MapPositionArray | undefined): MapPositionArray
53
- function add_shift(a: MapPositionArray | undefined, b: MapPositionArray | undefined): MapPositionArray | undefined
55
+ function add_shift(a: MapPositionArray | nil, b: MapPositionArray): MapPositionArray
56
+ function add_shift(a: MapPositionArray, b: MapPositionArray | nil): MapPositionArray
57
+ function add_shift(a: MapPositionArray | nil, b: MapPositionArray | nil): MapPositionArray | nil
54
58
 
55
59
  // omitted: add_shift_offset
56
60
 
57
- function mul_shift(shift: MapPositionArray, scale: number | undefined): MapPositionArray
58
- function mul_shift(shift: MapPositionArray | undefined, scale: number | undefined): MapPositionArray | undefined
61
+ function mul_shift(shift: MapPositionArray, scale: number | nil): MapPositionArray
62
+ function mul_shift(shift: MapPositionArray | nil, scale: number | nil): MapPositionArray | nil
59
63
 
60
64
  function format_number(amount: number, append_suffix?: boolean): string
61
65
 
@@ -68,11 +72,11 @@ declare module "util" {
68
72
  * entries are themselves tables, in which case they are recursively merged. Non-merged tables are deep-copied, so
69
73
  * that the result is brand new.
70
74
  */
71
- function merge<T extends object>(tables: T[]): T
75
+ function merge<T extends object>(tables: readonly T[]): T
72
76
 
73
- function insert_safe(entity: LuaEntity | undefined, item_dict: Record<string, number> | undefined): void
77
+ function insert_safe(entity: LuaEntity | nil, item_dict: Record<string, number> | nil): void
74
78
 
75
- function remove_safe(entity: LuaEntity | undefined, item_dict: Record<string, number> | undefined): void
79
+ function remove_safe(entity: LuaEntity | nil, item_dict: Record<string, number> | nil): void
76
80
 
77
81
  function split_whitespace(string: string): string[]
78
82
 
@@ -82,7 +86,7 @@ declare module "util" {
82
86
 
83
87
  function clamp(x: number, lower: number, upper: number): number
84
88
 
85
- // omitted: get_walkable_tile
89
+ function get_walkable_tile(): string
86
90
 
87
91
  // omitted: combine_icons
88
92
  // omitted: technology_icons. Create an issue if you really want to see these
@@ -110,7 +114,7 @@ declare module "util" {
110
114
 
111
115
  function remove_from_list<T>(list: T[], value: T): boolean
112
116
 
113
- function list_to_map<T extends keyof any>(list: T[]): Record<T, true>
114
- function list_to_map<T>(list: T[]): LuaTable<T, true>
115
- function list_to_map<T>(list: T): LuaTable<T[keyof T], true>
117
+ function list_to_map<V>(list: LuaPairsIterable<any, V>): LuaSet<NonNullable<V>>
118
+ function list_to_map<T extends AnyNotNil>(list: T[]): LuaSet<T>
119
+ function list_to_map<T extends AnyNotNil>(list: T): LuaSet<NonNullable<T[keyof T]>>
116
120
  }
package/Changelog.md DELETED
@@ -1,243 +0,0 @@
1
- # v1.7.1
2
-
3
- - Added proper nullablity to members with different read/write types
4
- - Deduped union types
5
-
6
- # v1.7.0
7
-
8
- - Updated to factorio version 1.1.67
9
-
10
- # v1.6.1
11
-
12
- - Fixed write type for `BoundingBox`.
13
- - Simplified types for BlueprintEntity.
14
-
15
- # v1.6.0
16
-
17
- - Updated to factorio version 1.1.64
18
-
19
- # v1.5.1
20
-
21
- - Added old `Read` types as deprecated type aliases of new types; to help with migration.
22
-
23
- # v1.5.0
24
-
25
- ### BREAKING
26
-
27
- - Read-only forms of concepts (the most common form used) is now specified with just the name; forms with a `Read` or `Table` suffix have been removed.
28
- - Write forms are now specified as either a union of table and array forms, or with a `Write` suffix for concepts.
29
- - For table-or-array concepts: `MapPositionRead` -> `MapPosition`, `MapPosition` -> `MapPosition | PositionArray`
30
- - For table concepts: `ScriptAreaRead` -> `ScriptArea`, `ScriptArea` -> `ScriptAreaWrite`
31
- - The minimum TSTL version has been increased to v1.6.1 (A bug with documentation comments was fixed in that version).
32
-
33
- ### Other
34
-
35
- - Updated to factorio version 1.1.63.
36
- - Upgraded to factorio api docs json version 3.
37
- - The new type `nil` is used instead of `undefined` (they are equivalent).
38
- - More complete type for `BlueprintEntity`.
39
- - Fixed missing read-write forms for more concepts.
40
- - Improved documentation comments (enabled by json docs version 3).
41
- - Improved documentation comments for variant parameter groups.
42
-
43
- # v1.4.0
44
-
45
- - Improve doc comments for enum concepts
46
- - Improve doc comment formatting
47
- - Improve types of concepts with literal union types
48
- - Add read-specific types to AutoplaceControl and ComparatorString
49
-
50
- # v1.3.2
51
-
52
- - Move "notes" comment into the main body of doc comment, instead of in @remarks. This works around #13.
53
- - Add manually defined overload for LuaControl::teleport().
54
-
55
- # v1.3.1
56
-
57
- - Use @linkplain instead of @link for web links. This hopefully works around issue #13
58
-
59
- # v1.3.0
60
-
61
- - Updated to factorio version 1.1.61
62
-
63
- # v1.2.0
64
-
65
- - Updated to factorio version 1.1.60
66
-
67
- # v1.1.0
68
-
69
- - Updated to factorio version 1.1.59
70
-
71
- # v1.0.0
72
-
73
- - This project now has all the features that was originally planned, and can now guarantee reasonable backwards compatibility for future releases.
74
- - Updated to factorio version 1.1.57
75
-
76
- # v0.20.0
77
-
78
- - Updated to factorio version 1.1.56
79
- - This is an **opt-in** feature: Some numeric types which represent indices/number,e.g. player_index, entity_number, are now branded numbers with their own type, e.g. `PlayerIndex` and `EntityNumber`. See the README for more info.
80
- - Added custom-index-template.d.ts to assist trying out custom changes to types in a project.
81
-
82
- # v0.19.0
83
-
84
- - Updated to factorio version 1.1.53
85
- - Updated to json api version 2
86
- - Improved documentation comments
87
-
88
- ## Changes
89
-
90
- - `Position`, `PositionArray`, and `PositionTable` have been replaced by `MapPosition`, `MapPositionArray`, and `MapPositionTable` respectively. These are now deprecated and may be removed in a future version.
91
-
92
- # v0.18.1
93
-
94
- - `TechnologyIdentification` now also has a more specific type when read.
95
-
96
- # v0.18.0
97
-
98
- - `ForceIdentification` and `ItemPrototypeIdentification` now have more specific types when read.
99
- - Properties which represent a flag concept now have the correct specific type, instead of `string`.
100
-
101
- # v0.17.1
102
-
103
- - Fixed documentation links for events
104
-
105
- # v0.17.0
106
-
107
- - Updated to factorio version 1.1.52
108
-
109
- # v0.16.0
110
-
111
- - `LuaCustomTable` can be iterated on in a for-of loop directly (without using `pairs`). This requires TSTL v1.3.0 or later.
112
- - TSTL dependency minimum version is now v1.3.0.
113
-
114
- # v0.15.0
115
-
116
- - Table or array concepts are now declared in table form wherever it is an "read" position.
117
- - This works with setter overloading for applicable properties: `player.color.x; player.color = [1, 1, 1]` is now valid!
118
- - This also applies to concepts/complex types which contain table_or_array properties.
119
- - Some concepts now also have a special form where it is known to be in a "read" position, where all table_or_array concepts are declared in table form. These concepts are suffixed with "Read", e.g. `ScriptAreaRead`.
120
- - Arrays which are known to be in a "write" only form (e.g. method parameters) now are marked readonly. This means you can now pass readonly arrays to these methods.
121
- - `MapPosition` is now a table or array concept.
122
- - Classes with subclasses are now declared with all properties, instead of an intersection of subclasses (reversion)
123
- - Subclass specializations added for some missing classes
124
-
125
- # v0.14.1
126
-
127
- - LuaStyle: `extra_margin/padding_when_activated` is now for subclass scroll_pane
128
-
129
- # v0.14.0
130
-
131
- - LuaStyle size, margin/padding setters now have more specific array types. These array types are `SizeArray` and `StyleValuesArray` for size and margin/padding, respectively.
132
- - `@noSelf` annotation is now only present when necessary.
133
- - For classes with subclasses:
134
- - The original class name (e.g. `LuaItemStack`) still contains attributes of all subclasses (same as before).
135
- - There is now a `Base` type (e.g. `BaseItemStack`) which only includes attributes common to all subclasses.
136
- - There is a separate type definition for each subclass, e.g. `BlueprintItem`. Note that one instance may still belong to multiple subclasses (the subclasses are not mutually exclusive).
137
- - The above two can be optionally used for stricter types.
138
-
139
- # v0.13.2
140
-
141
- - Fix: resize_to_sprite property should not be on subclass sprite-button
142
- - Fix: ChooseElemButtonSpec filters should be named elem_filters
143
- - Switch back to `/latest` api docs link
144
- - New version of web api docs is now active
145
-
146
- # v0.13.0
147
-
148
- - Update to factorio version 1.1.49
149
-
150
- # v0.12.0
151
-
152
- - Update to factorio version 1.1.48
153
-
154
- # v0.11.1
155
-
156
- - Localised strings now accept boolean and undefined.
157
-
158
- # v0.11.0
159
-
160
- - Update to factorio version 1.1.46
161
-
162
- # v0.10.0
163
-
164
- - LuaGuiElement.style and LuaControl.opened now have different get/set types (more specific get type).
165
- - The array form of LocalizedString is now readonly.
166
-
167
- # v0.9.0
168
-
169
- - Update to factorio version 1.1.43
170
- - The `defines.events `_type_ was renamed to `defines.Events`, to reduce confusion between the namespace/type
171
-
172
- # v0.8.0
173
-
174
- - All event types now explicitly extend `EventData`
175
- - Variant parameter groups without additional fields now have their own type, instead of all being grouped into `Other`
176
-
177
- # v0.7.3
178
-
179
- - Update to factorio version 1.1.42
180
- - No api changes, but improvements to descriptions
181
-
182
- # v0.7.2
183
-
184
- - Fix minor issue for event types
185
-
186
- # v0.7.0
187
-
188
- - Updated to factorio version 1.1.41 (no changes to lua api)
189
- - Improved smart types for events
190
-
191
- # v0.6.1
192
-
193
- - Added type for BlueprintControlBehavior
194
-
195
- # v0.6.0
196
-
197
- - Updated to factorio version 1.1.40
198
- - Fixed regression with duplicate strings in string union types
199
-
200
- # v0.5.0
201
-
202
- - Updated to factorio version 1.1.39
203
- - Documentation links now point to the new API docs website. More info here: https://forums.factorio.com/viewtopic.php?f=34&t=99797
204
-
205
- # v0.4.1
206
-
207
- ### Changed
208
-
209
- - LuaRemote.addInterface now lets remote functions take any arguments.
210
-
211
- # v0.4.0
212
-
213
- ## **BREAKING**
214
-
215
- - Only the latest version api is now provided.
216
- - It is now accessed using `typed-factorio/runtime` instead of `typed-factorio/<version>`
217
-
218
- ### Added
219
-
220
- - Basic types for settings and data stage. See README for more details.
221
- - Types for "util" and "mod-gui" lualib modules
222
-
223
- ### Fixed
224
-
225
- - LuaGuiElement::add with a literal now give diagnostic if you supply a field that shouldn't be there.
226
-
227
- ### Internal
228
-
229
- - Split generated files into multiple files
230
- - Improved compilation tests
231
-
232
- # v0.3.0
233
-
234
- - Added factorio version `1.1.38`
235
-
236
- # v0.2.0
237
-
238
- - `AnyBasic` now uses type `table` instead of type `Record<any, AnyBasic>`
239
- - README changes
240
-
241
- # v0.1.0
242
-
243
- - Initial release