Skip to content

Commit 74e9c3f

Browse files
committed
Make typescript typings stricter across
1 parent 8e2a9e9 commit 74e9c3f

File tree

10 files changed

+85
-6
lines changed

10 files changed

+85
-6
lines changed

lib/typedef.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,24 @@ const { ACTIONS } = Utils.ACTIONS;
190190
* @property {string|Blob} data - Attached data, such as CSV contents
191191
*/
192192

193+
/**
194+
* @typedef {Object} Frame - Represents a document frame, object frame, or property frame
195+
* in the viewer system. Frames are used to describe the structure and properties of data
196+
* being displayed or validated.
197+
* @property {string} [subject] - Subject identifier
198+
* @property {string} [property] - Property name
199+
* @property {string} [type] - Type information (e.g., xsd:string, schema:Person)
200+
* @property {*} [value] - Frame value
201+
* @property {number} [depth] - Depth in frame hierarchy
202+
* @property {string} [range] - Property range/type
203+
* @property {string} [label] - Display label
204+
* @property {Object} [parent] - Parent frame reference
205+
* @property {Array} [children] - Child frames
206+
* @property {string} [status] - Frame status: 'updated' | 'error' | 'new' | 'ok'
207+
* @property {boolean} [literal] - Whether this represents a literal value
208+
* @property {number} [index] - Index in parent collection
209+
* @property {Object} [frame] - Nested frame data
210+
* @property {string} [subjectClass] - Class of the subject
211+
*/
212+
193213
module.exports = {};

lib/viewer/frameRule.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
/* eslint-disable no-use-before-define */
99
const TerminusRule = require('./terminusRule');
1010

11+
/**
12+
* @typedef {import('../typedef').Frame} Frame
13+
*/
14+
1115
/**
1216
* @file Frame Rule
1317
* @license Apache Version 2
@@ -23,7 +27,7 @@ Object.setPrototypeOf(FrameRule.prototype, TerminusRule.TerminusRule.prototype);
2327
/**
2428
* Returns an array of rules that match the paased frame
2529
* @param {[FrameRule]} rules - array of rules to be tested
26-
* @param {Frame} frame - object frame, property frame or data from to be tested
30+
* @param {Frame | object} frame - document frame, object frame, or property frame to be tested
2731
* @param {function} [onmatch] - optional function to be called with args (frame, rule)
2832
* on each match
2933
*/

lib/viewer/tableConfig.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,10 @@ WOQLTableConfig.prototype.prettyPrint = function () {
124124
};
125125

126126
/**
127-
* @param {boolean} canfilter
128-
* @returns WOQLTableConfig
127+
* Gets or sets whether the table is filterable
128+
* @param {boolean} [canfilter] - If provided, sets the filterable state
129+
* @returns {boolean|WOQLTableConfig} - Returns the filterable state (boolean) when called
130+
* without arguments, or returns this instance (WOQLTableConfig) for chaining when setting
129131
*/
130132

131133
WOQLTableConfig.prototype.filterable = function (canfilter) {

lib/viewer/terminusRule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ TerminusRule.prototype.literal = function (tf) {
2020
};
2121

2222
/**
23-
* @param {[TYPE_URLS]} list - parameters are types identified by prefixed URLS (xsd:string...)
23+
* @param {...string} list - parameters are types identified by prefixed URLS (xsd:string...)
2424
*/
2525
TerminusRule.prototype.type = function (...list) {
2626
if (typeof list === 'undefined' || list.length === 0) {

lib/viewer/woqlChooser.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ const WOQLChooserConfig = require('./chooserConfig');
66
const UTILS = require('../utils');
77
const { WOQLRule } = require('./woqlRule');
88

9+
/**
10+
* @typedef {import('../woqlClient')} WOQLClient
11+
*/
12+
913
/**
1014
* Very simple implementation of a WOQL backed chooser
1115
* Makes a drop down from a WOQL query - configuration tells it which columns to use...

lib/viewer/woqlResult.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
const UTILS = require('../utils');
99
const WOQL = require('../woql');
1010
const WOQLQ = require('./woqlPaging');
11+
12+
/**
13+
* @typedef {import('../query/woqlCore')} WOQLQuery
14+
*/
15+
1116
/**
1217
* @module WOQLResult
1318
* @license Apache Version 2

lib/viewer/woqlStream.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
const WOQLStreamConfig = require('./streamConfig');
22

3+
/**
4+
* @typedef {import('../woqlClient')} WOQLClient
5+
*/
6+
37
/**
48
* @param {WOQLClient} client
59
* @param {WOQLStreamConfig} config

lib/woql.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,9 @@ WOQL.evaluate = function (arithExp, resultVarName) {
522522
* @example
523523
* let [result] = vars("result")
524524
* eval(plus(2, minus(3, 1)), result)
525+
* @deprecated Use {@link evaluate} instead. The name 'eval' conflicts with JavaScript's
526+
* built-in eval in strict mode.
527+
* @internal
525528
*/
526529
WOQL.eval = function (arithExp, resultVarName) {
527530
return new WOQLQuery().eval(arithExp, resultVarName);
@@ -1350,7 +1353,7 @@ WOQL.iri = function (val) {
13501353
/**
13511354
* Generates javascript variables for use as WOQL variables within a query
13521355
* @param {...string} varNames
1353-
* @returns {array<Var>} an array of javascript variables which can be dereferenced using the
1356+
* @returns {Array<Var>} an array of javascript variables which can be dereferenced using the
13541357
* array destructuring operation
13551358
* @example
13561359
* const [a, b, c] = WOQL.vars("a", "b", "c")
@@ -1364,7 +1367,7 @@ WOQL.vars = function (...varNames) {
13641367
/**
13651368
* Generates unique javascript variables for use as WOQL variables within a query
13661369
* @param {...string} varNames
1367-
* @returns {array<Var>} an array of javascript variables which can be dereferenced using the
1370+
* @returns {Array<Var>} an array of javascript variables which can be dereferenced using the
13681371
* array destructuring operation
13691372
* @example
13701373
* const [a, b, c] = WOQL.vars("a", "b", "c")

lib/woqlClient.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ const ConnectionConfig = require('./connectionConfig');
1414
const WOQL = require('./woql');
1515
const WOQLQuery = require('./query/woqlCore');
1616

17+
/**
18+
* @typedef {import('./typedef').NamedResourceData} NamedResourceData
19+
*/
20+
1721
/**
1822
* @license Apache Version 2
1923
* @class

scripts/fix-eval-export.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env node
2+
/* eslint-disable no-console */
3+
4+
/**
5+
* Post-process generated .d.ts files to fix the 'eval' export issue.
6+
* The function 'eval' is a reserved keyword in strict mode, so we rename it
7+
* in the type definitions while keeping the JavaScript implementation for backward compatibility.
8+
*/
9+
10+
const fs = require('fs');
11+
const path = require('path');
12+
13+
const woqlDtsPath = path.join(__dirname, '../dist/typescript/lib/woql.d.ts');
14+
15+
if (!fs.existsSync(woqlDtsPath)) {
16+
console.error(`Error: ${woqlDtsPath} not found. Run 'npm run generate-types' first.`);
17+
process.exit(1);
18+
}
19+
20+
let content = fs.readFileSync(woqlDtsPath, 'utf8');
21+
22+
// Remove the eval export line (it's deprecated, use evaluate instead)
23+
const evalExportRegex = /export declare function eval\([^)]*\): [^;]+;[\r\n]*/g;
24+
const originalLength = content.length;
25+
26+
content = content.replace(evalExportRegex, '');
27+
28+
if (content.length < originalLength) {
29+
fs.writeFileSync(woqlDtsPath, content, 'utf8');
30+
console.log('>> Removed eval export from woql.d.ts (use evaluate() instead)');
31+
} else {
32+
console.log('>> No eval export found in woql.d.ts, no workaround needed');
33+
}

0 commit comments

Comments
 (0)