@irsdk-node/native 4.1.0 → 5.0.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.
- package/LICENSE.md +9 -0
- package/README.md +90 -21
- package/dist/cjs/index.cjs +9453 -0
- package/dist/esm/index.js +9440 -0
- package/dist/{INativeSDK.d.ts → types/INativeSDK.d.ts} +9 -0
- package/dist/{MockSdk.d.ts → types/MockSdk.d.ts} +2 -1
- package/dist/types/index.d.ts +4 -0
- package/lib/irsdk_client.cpp +94 -94
- package/lib/irsdk_client.h +23 -23
- package/lib/irsdk_defines.h +136 -82
- package/lib/irsdk_diskclient.cpp +997 -0
- package/lib/irsdk_diskclient.h +205 -0
- package/lib/irsdk_node.cc +1 -1
- package/lib/irsdk_utils.cpp +71 -71
- package/lib/yaml_parser.cpp +41 -41
- package/lib/yaml_parser.h +1 -1
- package/package.json +25 -27
- package/prebuilds/darwin-arm64/@irsdk-node+native.node +0 -0
- package/prebuilds/win32-x64/@irsdk-node+native.node +0 -0
- package/dist/INativeSDK.js +0 -2
- package/dist/MockSdk.js +0 -70
- package/dist/mock-data/loader.js +0 -41
- package/dist/mock-data/session.json +0 -4305
- package/dist/mock-data/telemetry.json +0 -4986
- package/index.d.ts +0 -87
- package/index.js +0 -36
- /package/dist/{mock-data → types/mock-data}/loader.d.ts +0 -0
package/lib/yaml_parser.cpp
CHANGED
|
@@ -4,14 +4,14 @@ All rights reserved.
|
|
|
4
4
|
|
|
5
5
|
Redistribution and use in source and binary forms, with or without
|
|
6
6
|
modification, are permitted provided that the following conditions are met:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
* Redistributions of source code must retain the above copyright
|
|
8
|
+
notice, this list of conditions and the following disclaimer.
|
|
9
|
+
* Redistributions in binary form must reproduce the above copyright
|
|
10
|
+
notice, this list of conditions and the following disclaimer in the
|
|
11
|
+
documentation and/or other materials provided with the distribution.
|
|
12
|
+
* Neither the name of iRacing.com Motorsport Simulations nor the
|
|
13
|
+
names of its contributors may be used to endorse or promote products
|
|
14
|
+
derived from this software without specific prior written permission.
|
|
15
15
|
|
|
16
16
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
17
17
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
@@ -37,9 +37,9 @@ enum yaml_state {
|
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
// super simple YAML parser
|
|
40
|
-
bool parseYaml(const char
|
|
40
|
+
bool parseYaml(const char* data, const char* path, const char** val, int* len)
|
|
41
41
|
{
|
|
42
|
-
if(data && path && val && len)
|
|
42
|
+
if (data && path && val && len)
|
|
43
43
|
{
|
|
44
44
|
// make sure we set this to something
|
|
45
45
|
*val = NULL;
|
|
@@ -48,39 +48,39 @@ bool parseYaml(const char *data, const char* path, const char **val, int *len)
|
|
|
48
48
|
int depth = 0;
|
|
49
49
|
yaml_state state = space;
|
|
50
50
|
|
|
51
|
-
const char
|
|
51
|
+
const char* keystr = NULL;
|
|
52
52
|
int keylen = 0;
|
|
53
53
|
|
|
54
|
-
const char
|
|
54
|
+
const char* valuestr = NULL;
|
|
55
55
|
int valuelen = 0;
|
|
56
56
|
|
|
57
|
-
const char
|
|
57
|
+
const char* pathptr = path;
|
|
58
58
|
int pathdepth = 0;
|
|
59
59
|
|
|
60
|
-
while(*data)
|
|
60
|
+
while (*data)
|
|
61
61
|
{
|
|
62
|
-
switch(*data)
|
|
62
|
+
switch (*data)
|
|
63
63
|
{
|
|
64
64
|
case ' ':
|
|
65
|
-
if(state == newline)
|
|
65
|
+
if (state == newline)
|
|
66
66
|
state = space;
|
|
67
|
-
if(state == space)
|
|
67
|
+
if (state == space)
|
|
68
68
|
depth++;
|
|
69
|
-
else if(state == key)
|
|
69
|
+
else if (state == key)
|
|
70
70
|
keylen++;
|
|
71
|
-
else if(state == value)
|
|
71
|
+
else if (state == value)
|
|
72
72
|
valuelen++;
|
|
73
73
|
break;
|
|
74
74
|
case '-':
|
|
75
|
-
if(state == newline)
|
|
75
|
+
if (state == newline)
|
|
76
76
|
state = space;
|
|
77
|
-
if(state == space)
|
|
77
|
+
if (state == space)
|
|
78
78
|
depth++;
|
|
79
|
-
else if(state == key)
|
|
79
|
+
else if (state == key)
|
|
80
80
|
keylen++;
|
|
81
|
-
else if(state == value)
|
|
81
|
+
else if (state == value)
|
|
82
82
|
valuelen++;
|
|
83
|
-
else if(state == keysep)
|
|
83
|
+
else if (state == keysep)
|
|
84
84
|
{
|
|
85
85
|
state = value;
|
|
86
86
|
valuestr = data;
|
|
@@ -88,50 +88,50 @@ bool parseYaml(const char *data, const char* path, const char **val, int *len)
|
|
|
88
88
|
}
|
|
89
89
|
break;
|
|
90
90
|
case ':':
|
|
91
|
-
if(state == key)
|
|
91
|
+
if (state == key)
|
|
92
92
|
{
|
|
93
93
|
state = keysep;
|
|
94
94
|
keylen++;
|
|
95
95
|
}
|
|
96
|
-
else if(state == keysep)
|
|
96
|
+
else if (state == keysep)
|
|
97
97
|
{
|
|
98
98
|
state = value;
|
|
99
99
|
valuestr = data;
|
|
100
100
|
}
|
|
101
|
-
else if(state == value)
|
|
101
|
+
else if (state == value)
|
|
102
102
|
valuelen++;
|
|
103
103
|
break;
|
|
104
104
|
case '\n':
|
|
105
105
|
case '\r':
|
|
106
|
-
if(state != newline)
|
|
106
|
+
if (state != newline)
|
|
107
107
|
{
|
|
108
|
-
if(depth < pathdepth)
|
|
108
|
+
if (depth < pathdepth)
|
|
109
109
|
{
|
|
110
110
|
return false;
|
|
111
111
|
}
|
|
112
|
-
else if(keylen && 0 == strncmp(keystr, pathptr, keylen))
|
|
112
|
+
else if (keylen && 0 == strncmp(keystr, pathptr, keylen))
|
|
113
113
|
{
|
|
114
114
|
bool found = true;
|
|
115
115
|
//do we need to test the value?
|
|
116
|
-
if(*(pathptr+keylen) == '{')
|
|
116
|
+
if (*(pathptr + keylen) == '{')
|
|
117
117
|
{
|
|
118
118
|
//search for closing brace
|
|
119
|
-
int pathvaluelen = keylen + 1;
|
|
120
|
-
while(*(pathptr+pathvaluelen) && *(pathptr+pathvaluelen) != '}')
|
|
121
|
-
pathvaluelen++;
|
|
119
|
+
int pathvaluelen = keylen + 1;
|
|
120
|
+
while (*(pathptr + pathvaluelen) && *(pathptr + pathvaluelen) != '}')
|
|
121
|
+
pathvaluelen++;
|
|
122
122
|
|
|
123
|
-
if(valuelen == pathvaluelen - (keylen+1) && 0 == strncmp(valuestr, (pathptr+keylen+1), valuelen))
|
|
123
|
+
if (valuelen == pathvaluelen - (keylen + 1) && 0 == strncmp(valuestr, (pathptr + keylen + 1), valuelen))
|
|
124
124
|
pathptr += valuelen + 2;
|
|
125
125
|
else
|
|
126
126
|
found = false;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
if(found)
|
|
129
|
+
if (found)
|
|
130
130
|
{
|
|
131
131
|
pathptr += keylen;
|
|
132
132
|
pathdepth = depth;
|
|
133
133
|
|
|
134
|
-
if(*pathptr == '\0')
|
|
134
|
+
if (*pathptr == '\0')
|
|
135
135
|
{
|
|
136
136
|
*val = valuestr;
|
|
137
137
|
*len = valuelen;
|
|
@@ -147,21 +147,21 @@ bool parseYaml(const char *data, const char* path, const char **val, int *len)
|
|
|
147
147
|
state = newline;
|
|
148
148
|
break;
|
|
149
149
|
default:
|
|
150
|
-
if(state == space || state == newline)
|
|
150
|
+
if (state == space || state == newline)
|
|
151
151
|
{
|
|
152
152
|
state = key;
|
|
153
153
|
keystr = data;
|
|
154
154
|
keylen = 0; //redundant?
|
|
155
155
|
}
|
|
156
|
-
else if(state == keysep)
|
|
156
|
+
else if (state == keysep)
|
|
157
157
|
{
|
|
158
158
|
state = value;
|
|
159
159
|
valuestr = data;
|
|
160
160
|
valuelen = 0; //redundant?
|
|
161
161
|
}
|
|
162
|
-
if(state == key)
|
|
162
|
+
if (state == key)
|
|
163
163
|
keylen++;
|
|
164
|
-
if(state == value)
|
|
164
|
+
if (state == value)
|
|
165
165
|
valuelen++;
|
|
166
166
|
break;
|
|
167
167
|
}
|
package/lib/yaml_parser.h
CHANGED
|
@@ -29,6 +29,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
29
29
|
#define YAML_PARSER_H
|
|
30
30
|
|
|
31
31
|
// super simple YAML parser
|
|
32
|
-
bool parseYaml(const char
|
|
32
|
+
bool parseYaml(const char* data, const char* path, const char** val, int* len);
|
|
33
33
|
|
|
34
34
|
#endif //YAML_PARSER_H
|
package/package.json
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@irsdk-node/native",
|
|
3
|
-
"version": "
|
|
4
|
-
"author":
|
|
5
|
-
"name": "Matt Bengston",
|
|
6
|
-
"email": "bengsfort@gmail.com",
|
|
7
|
-
"url": "http://bengsfort.dev/"
|
|
8
|
-
},
|
|
3
|
+
"version": "5.0.0",
|
|
4
|
+
"author": "Matt Bengston <bengsfort@gmail.com> (https://bengsfort.dev/)",
|
|
9
5
|
"bugs": {
|
|
10
6
|
"email": "bengsfort@gmail.com",
|
|
11
7
|
"url": "https://github.com/bengsfort/irsdk-node/issues"
|
|
@@ -17,53 +13,55 @@
|
|
|
17
13
|
"package.json",
|
|
18
14
|
"./dist",
|
|
19
15
|
"./lib",
|
|
20
|
-
"./index.js",
|
|
21
16
|
"./index.d.ts",
|
|
22
17
|
"./prebuilds",
|
|
23
18
|
"./scripts",
|
|
24
19
|
"./binding.gyp",
|
|
25
20
|
"./README.md"
|
|
26
21
|
],
|
|
22
|
+
"type": "module",
|
|
23
|
+
"main": "./dist/cjs/index.cjs",
|
|
24
|
+
"module": "./dist/esm/index.js",
|
|
25
|
+
"types": "./dist/types/index.d.ts",
|
|
27
26
|
"exports": {
|
|
28
27
|
".": {
|
|
29
|
-
"types": "./index.d.ts",
|
|
30
|
-
"
|
|
28
|
+
"types": "./dist/types/index.d.ts",
|
|
29
|
+
"import": "./dist/esm/index.js",
|
|
30
|
+
"require": "./dist/cjs/index.cjs"
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
|
-
"
|
|
34
|
-
"types": "./index.d.ts",
|
|
33
|
+
"prettier": "@bengsfort/eslint-config-flat/prettier.config.js",
|
|
35
34
|
"dependencies": {
|
|
36
35
|
"bindings": "^1.5.0",
|
|
37
36
|
"js-yaml": "^4.1.0",
|
|
38
37
|
"node-addon-api": "^8.2.1",
|
|
39
|
-
"node-gyp": "^
|
|
38
|
+
"node-gyp": "^11.5.0",
|
|
40
39
|
"node-gyp-build": "^4.8.4",
|
|
41
|
-
"@irsdk-node/types": "^
|
|
40
|
+
"@irsdk-node/types": "^4.0.0"
|
|
42
41
|
},
|
|
43
42
|
"devDependencies": {
|
|
43
|
+
"@bengsfort/eslint-config-flat": "^0.2.5",
|
|
44
44
|
"@types/js-yaml": "^4.0.9",
|
|
45
|
-
"@
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"eslint": "^8.4.1",
|
|
49
|
-
"eslint-config-airbnb-base": "^15.0.0",
|
|
50
|
-
"eslint-plugin-import": "^2.25.3",
|
|
51
|
-
"eslint-plugin-prettier": "^4.0.0",
|
|
45
|
+
"@types/node": "^24.8.1",
|
|
46
|
+
"esbuild": "^0.25.11",
|
|
47
|
+
"eslint": "^9.38.0",
|
|
52
48
|
"node-notifier": "^10.0.0",
|
|
53
49
|
"prebuildify": "^6.0.1",
|
|
54
|
-
"
|
|
55
|
-
"typescript": "^4.5.2"
|
|
50
|
+
"typescript": "^5.9.3"
|
|
56
51
|
},
|
|
57
52
|
"scripts": {
|
|
58
53
|
"install": "node-gyp-build",
|
|
54
|
+
"clean": "pnpm run \"/^clean:.*/\"",
|
|
59
55
|
"clean:ts": "rm -rf dist *.tsbuildinfo",
|
|
60
56
|
"clean:cpp": "rm -rf ./prebuilds ./build",
|
|
61
|
-
"
|
|
62
|
-
"build": "
|
|
63
|
-
"build:ts": "tsc --build --force",
|
|
57
|
+
"build": "pnpm run clean && pnpm run \"/^build:(ts|types|cpp)$/\"",
|
|
58
|
+
"build:ts": "node esbuild.js",
|
|
64
59
|
"build:cpp": "prebuildify --napi --electron-compat",
|
|
65
|
-
"
|
|
66
|
-
"
|
|
60
|
+
"build:types": "tsc --emitDeclarationOnly",
|
|
61
|
+
"watch": "pnpm run \"/^watch:.*/\"",
|
|
62
|
+
"watch:ts": "node esbuild.js --watch",
|
|
63
|
+
"watch:types": "tsc --watch --emitDeclarationOnly",
|
|
64
|
+
"lint": "eslint",
|
|
67
65
|
"check-types": "tsc --noEmit",
|
|
68
66
|
"generate-types": "node ./scripts/generate-var-types.js"
|
|
69
67
|
}
|
|
Binary file
|
|
Binary file
|
package/dist/INativeSDK.js
DELETED
package/dist/MockSdk.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MockSDK = void 0;
|
|
4
|
-
const loader_1 = require("./mock-data/loader");
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
6
|
-
let MOCK_TELEMETRY = null;
|
|
7
|
-
let MOCK_SESSION = null;
|
|
8
|
-
/**
|
|
9
|
-
* Mock SDK class intended for use on non-win32 platforms for development.
|
|
10
|
-
* Implements the native sdk interface supplemented with mock data suitable for
|
|
11
|
-
* iterating on projects with.
|
|
12
|
-
*
|
|
13
|
-
* @todo - This should really be handled differently, for example via a wrapper
|
|
14
|
-
* class around the native class that gets exposed.
|
|
15
|
-
*/
|
|
16
|
-
class MockSDK {
|
|
17
|
-
currDataVersion = 1;
|
|
18
|
-
isMocked = true;
|
|
19
|
-
enableLogging = false;
|
|
20
|
-
_isRunning = false;
|
|
21
|
-
constructor() {
|
|
22
|
-
this._loadMockData().catch((reason) => {
|
|
23
|
-
console.error('Error loading mock data for mock SDK:', reason);
|
|
24
|
-
});
|
|
25
|
-
console.warn('Attempting to access iRacing SDK on unsupported platform!', '\nReturning mock SDK for testing purposes. (Only win32 supported)');
|
|
26
|
-
}
|
|
27
|
-
async _loadMockData() {
|
|
28
|
-
const [session, telemetry] = await Promise.all([
|
|
29
|
-
!MOCK_SESSION ? (0, loader_1.loadMockSessionData)() : Promise.resolve(MOCK_SESSION),
|
|
30
|
-
!MOCK_TELEMETRY ? (0, loader_1.loadMockTelemetry)() : Promise.resolve(MOCK_TELEMETRY),
|
|
31
|
-
]);
|
|
32
|
-
MOCK_SESSION = session;
|
|
33
|
-
MOCK_TELEMETRY = telemetry;
|
|
34
|
-
}
|
|
35
|
-
startSDK() {
|
|
36
|
-
this._isRunning = true;
|
|
37
|
-
return true;
|
|
38
|
-
}
|
|
39
|
-
stopSDK() {
|
|
40
|
-
this._isRunning = false;
|
|
41
|
-
}
|
|
42
|
-
isRunning() {
|
|
43
|
-
return this._isRunning;
|
|
44
|
-
}
|
|
45
|
-
waitForData(_timeout) {
|
|
46
|
-
return this._isRunning;
|
|
47
|
-
}
|
|
48
|
-
getSessionData() {
|
|
49
|
-
return MOCK_SESSION ?? '';
|
|
50
|
-
}
|
|
51
|
-
getTelemetryData() {
|
|
52
|
-
if (!MOCK_TELEMETRY) {
|
|
53
|
-
throw new Error('Attempted accessing mock telemetry before it was loaded.');
|
|
54
|
-
}
|
|
55
|
-
return MOCK_TELEMETRY;
|
|
56
|
-
}
|
|
57
|
-
getTelemetryVariable(name) {
|
|
58
|
-
if (!MOCK_TELEMETRY) {
|
|
59
|
-
throw new Error('Attempted accessing mock telemetry before it was loaded.');
|
|
60
|
-
}
|
|
61
|
-
if (typeof name === 'number') {
|
|
62
|
-
return Object.values(MOCK_TELEMETRY)[name];
|
|
63
|
-
}
|
|
64
|
-
return MOCK_TELEMETRY[name];
|
|
65
|
-
}
|
|
66
|
-
broadcast(...args) {
|
|
67
|
-
console.log('Mocking SDK call:', ...args);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.MockSDK = MockSDK;
|
package/dist/mock-data/loader.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// eslint-disable @typescript-eslint/no-unsafe-return
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
-
if (mod && mod.__esModule) return mod;
|
|
21
|
-
var result = {};
|
|
22
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
-
__setModuleDefault(result, mod);
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
|
-
};
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.loadMockTelemetry = exports.loadMockSessionData = void 0;
|
|
31
|
-
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
32
|
-
const loadMockSessionData = async () => {
|
|
33
|
-
const json = await Promise.resolve().then(() => __importStar(require('./session.json')));
|
|
34
|
-
return js_yaml_1.default.dump(json.default);
|
|
35
|
-
};
|
|
36
|
-
exports.loadMockSessionData = loadMockSessionData;
|
|
37
|
-
const loadMockTelemetry = async () => {
|
|
38
|
-
const json = await Promise.resolve().then(() => __importStar(require('./telemetry.json')));
|
|
39
|
-
return json.default;
|
|
40
|
-
};
|
|
41
|
-
exports.loadMockTelemetry = loadMockTelemetry;
|