Skip to content

Commit bd6466a

Browse files
committed
chore: apply oxfmt formatting
Run `oxfmt --write` across the whole repo. Pure formatting commit; no behavior change. Folded in is one directive move from `// eslint-disable-line` on the body of a `for-in` to `// eslint-disable-next-line` above the loop, since oxfmt split the trailing comment onto the next line which made it apply to the wrong statement.
1 parent bbbbf83 commit bd6466a

67 files changed

Lines changed: 2798 additions & 1505 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/actor-memory-expression/src/memory_calculator.ts

Lines changed: 57 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,23 @@ const math = create({
7070
const { compile } = math;
7171

7272
// Disable potentially dangerous functions
73-
math.import({
74-
// We disable evaluate to prevent users from calling it inside their expressions.
75-
// For example: defaultMemoryMbytes = "evaluate('2 + 2')"
76-
evaluate() { throw new Error('Function evaluate is disabled.'); },
77-
compile() { throw new Error('Function compile is disabled.'); },
78-
// We need to disable it, because compileDependencies imports parseDependencies.
79-
parse() { throw new Error('Function parse is disabled.'); },
80-
}, { override: true });
73+
math.import(
74+
{
75+
// We disable evaluate to prevent users from calling it inside their expressions.
76+
// For example: defaultMemoryMbytes = "evaluate('2 + 2')"
77+
evaluate() {
78+
throw new Error('Function evaluate is disabled.');
79+
},
80+
compile() {
81+
throw new Error('Function compile is disabled.');
82+
},
83+
// We need to disable it, because compileDependencies imports parseDependencies.
84+
parse() {
85+
throw new Error('Function parse is disabled.');
86+
},
87+
},
88+
{ override: true },
89+
);
8190

8291
/**
8392
* Safely retrieves a nested property from an object using a dot-notation string path.
@@ -89,17 +98,17 @@ math.import({
8998
* @param path A dot-separated string representing the nested path (e.g., "input.payload.size").
9099
* @param defaultVal The value to return if the path is not found or the value is `null` or `undefined`.
91100
* @returns The retrieved value, or `defaultVal` if the path is unreachable.
92-
*/
101+
*/
93102
const customGetFunc = (obj: any, path: string, defaultVal?: number) => {
94-
return (path.split('.').reduce((current, key) => current?.[key], obj)) ?? defaultVal;
103+
return path.split('.').reduce((current, key) => current?.[key], obj) ?? defaultVal;
95104
};
96105

97106
/**
98107
* Rounds a number to the closest power of 2.
99108
* The result is clamped to the allowed range (ACTOR_LIMITS.MIN_RUN_MEMORY_MBYTES - ACTOR_LIMITS.MAX_RUN_MEMORY_MBYTES).
100109
* @param num The number to round.
101110
* @returns The closest power of 2 within min/max range.
102-
*/
111+
*/
103112
const roundToClosestPowerOf2 = (num: number): number => {
104113
if (typeof num !== 'number' || Number.isNaN(num) || !Number.isFinite(num)) {
105114
throw new Error(`Calculated memory value is not a valid number: ${num}.`);
@@ -139,44 +148,46 @@ const roundToClosestPowerOf2 = (num: number): number => {
139148
const processTemplateVariables = (defaultMemoryMbytes: string): string => {
140149
const variableRegex = /{{\s*([a-zA-Z0-9_.]+)\s*}}/g;
141150

142-
const processedExpression = defaultMemoryMbytes.replace(
143-
variableRegex,
144-
(_, variableName: string) => {
145-
// 1. Check if the variable is accessing input (e.g. {{input.someValue}})
146-
// We do not validate the specific property name because `input` is dynamic.
147-
if (variableName.startsWith('input.')) {
148-
return variableName;
151+
const processedExpression = defaultMemoryMbytes.replace(variableRegex, (_, variableName: string) => {
152+
// 1. Check if the variable is accessing input (e.g. {{input.someValue}})
153+
// We do not validate the specific property name because `input` is dynamic.
154+
if (variableName.startsWith('input.')) {
155+
return variableName;
156+
}
157+
158+
// 2. Check if the variable is accessing runOptions (e.g. {{runOptions.memoryMbytes}}) and validate the keys.
159+
if (variableName.startsWith('runOptions.')) {
160+
const key = variableName.slice('runOptions.'.length);
161+
if (!ALLOWED_RUN_OPTION_KEYS.has(key as keyof ActorRunOptions)) {
162+
throw new Error(
163+
`Invalid variable '{{${variableName}}}' in expression. Only the following runOptions are allowed: ${Array.from(
164+
ALLOWED_RUN_OPTION_KEYS,
165+
)
166+
.map((k) => `runOptions.${k}`)
167+
.join(', ')}.`,
168+
);
149169
}
170+
return variableName;
171+
}
150172

151-
// 2. Check if the variable is accessing runOptions (e.g. {{runOptions.memoryMbytes}}) and validate the keys.
152-
if (variableName.startsWith('runOptions.')) {
153-
const key = variableName.slice('runOptions.'.length);
154-
if (!ALLOWED_RUN_OPTION_KEYS.has(key as keyof ActorRunOptions)) {
155-
throw new Error(
156-
`Invalid variable '{{${variableName}}}' in expression. Only the following runOptions are allowed: ${Array.from(ALLOWED_RUN_OPTION_KEYS).map((k) => `runOptions.${k}`).join(', ')}.`,
157-
);
158-
}
159-
return variableName;
160-
}
161-
162-
// 3. Throw error for unrecognized variables (e.g. {{someVariable}})
163-
throw new Error(
164-
`Invalid variable '{{${variableName}}}' in expression.`,
165-
);
166-
},
167-
);
173+
// 3. Throw error for unrecognized variables (e.g. {{someVariable}})
174+
throw new Error(`Invalid variable '{{${variableName}}}' in expression.`);
175+
});
168176

169177
return processedExpression;
170178
};
171179

172180
/*
173-
* Retrieves a compiled expression from the cache or compiles it if not present.
174-
*
175-
* @param expression The expression string to compile.
176-
* @param cache An optional cache to store/retrieve compiled expressions.
177-
* @returns The compiled CompilationResult.
178-
*/
179-
const getCompiledExpression = async (expression: string, cache: CompilationCache | undefined): Promise<CompilationResult> => {
181+
* Retrieves a compiled expression from the cache or compiles it if not present.
182+
*
183+
* @param expression The expression string to compile.
184+
* @param cache An optional cache to store/retrieve compiled expressions.
185+
* @returns The compiled CompilationResult.
186+
*/
187+
const getCompiledExpression = async (
188+
expression: string,
189+
cache: CompilationCache | undefined,
190+
): Promise<CompilationResult> => {
180191
if (!cache) {
181192
return compile(expression);
182193
}
@@ -199,14 +210,16 @@ const getCompiledExpression = async (expression: string, cache: CompilationCache
199210
* @param context The `MemoryEvaluationContext` (containing `input` and `runOptions`) available to the expression.
200211
* @param options.cache Optional synchronous cache. Since compiled functions cannot be saved to a database/Redis, they are kept in local memory.
201212
* @returns The calculated memory value rounded to the closest power of 2 and clamped within allowed limits.
202-
*/
213+
*/
203214
export const calculateRunDynamicMemory = async (
204215
defaultMemoryMbytes: string,
205216
context: MemoryEvaluationContext,
206217
options: { cache: CompilationCache } | undefined = undefined,
207218
) => {
208219
if (defaultMemoryMbytes.length > DEFAULT_MEMORY_MBYTES_EXPRESSION_MAX_LENGTH) {
209-
throw new Error(`The defaultMemoryMbytes expression is too long. Max length is ${DEFAULT_MEMORY_MBYTES_EXPRESSION_MAX_LENGTH} characters.`);
220+
throw new Error(
221+
`The defaultMemoryMbytes expression is too long. Max length is ${DEFAULT_MEMORY_MBYTES_EXPRESSION_MAX_LENGTH} characters.`,
222+
);
210223
}
211224

212225
// Replaces all occurrences of {{variable}} with variable

packages/actor-memory-expression/src/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ export type ActorRunOptions = {
88
maxItems?: number;
99
maxTotalChargeUsd?: number;
1010
restartOnError?: boolean;
11-
}
11+
};
1212

1313
export type MemoryEvaluationContext = {
1414
runOptions: ActorRunOptions;
1515
input: Record<string, unknown>;
16-
}
16+
};
1717

1818
export type CompilationCache = {
1919
get: (expression: string) => Promise<EvalFunction | null>;
2020
set: (expression: string, compilationResult: EvalFunction) => Promise<void>;
2121
size: () => Promise<number>;
22-
}
22+
};
2323

2424
export type CompilationResult = EvalFunction;

packages/consts/src/consts.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -378,13 +378,9 @@ export const INTEGER_ENV_VARS = [
378378
APIFY_ENV_VARS.SYSTEM_INFO_INTERVAL_MILLIS,
379379
] as const;
380380

381-
export const COMMA_SEPARATED_LIST_ENV_VARS = [
382-
ACTOR_ENV_VARS.BUILD_TAGS,
383-
] as const;
381+
export const COMMA_SEPARATED_LIST_ENV_VARS = [ACTOR_ENV_VARS.BUILD_TAGS] as const;
384382

385-
export const JSON_ENCODED_ENV_VARS = [
386-
ACTOR_ENV_VARS.STORAGES_JSON,
387-
] as const;
383+
export const JSON_ENCODED_ENV_VARS = [ACTOR_ENV_VARS.STORAGES_JSON] as const;
388384

389385
/**
390386
* Dictionary of names of build-time variables passed to the Actor's Docker build process.
@@ -577,16 +573,10 @@ export const WEBHOOK_DEFAULT_PAYLOAD_TEMPLATE = `{
577573
"eventData": {{eventData}},
578574
"resource": {{resource}}
579575
}`;
580-
export const WEBHOOK_ALLOWED_PAYLOAD_VARIABLES = new Set([
581-
'userId',
582-
'createdAt',
583-
'eventType',
584-
'eventData',
585-
'resource',
586-
]);
576+
export const WEBHOOK_ALLOWED_PAYLOAD_VARIABLES = new Set(['userId', 'createdAt', 'eventType', 'eventData', 'resource']);
587577

588578
// Max allowed size of files in multi-file editor
589-
export const MAX_MULTIFILE_BYTES = 3 * (1024 ** 2); // 3MB
579+
export const MAX_MULTIFILE_BYTES = 3 * 1024 ** 2; // 3MB
590580

591581
// Formats for multi-file editor files
592582
export const SOURCE_FILE_FORMATS = {
@@ -666,7 +656,7 @@ export const STORAGE_GENERAL_ACCESS = {
666656
ANYONE_WITH_NAME_CAN_READ: 'ANYONE_WITH_NAME_CAN_READ',
667657
} as const;
668658

669-
export type STORAGE_GENERAL_ACCESS = ValueOf<typeof STORAGE_GENERAL_ACCESS>
659+
export type STORAGE_GENERAL_ACCESS = ValueOf<typeof STORAGE_GENERAL_ACCESS>;
670660

671661
/**
672662
* Run setting determining how others can access the run.
@@ -684,7 +674,7 @@ export const RUN_GENERAL_ACCESS = {
684674
ANYONE_WITH_ID_CAN_READ: 'ANYONE_WITH_ID_CAN_READ',
685675
} as const;
686676

687-
export type RUN_GENERAL_ACCESS = ValueOf<typeof RUN_GENERAL_ACCESS>
677+
export type RUN_GENERAL_ACCESS = ValueOf<typeof RUN_GENERAL_ACCESS>;
688678

689679
/**
690680
* Determines permissions that the Actor requires to run.

packages/consts/src/regexs.ts

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Parts for building an email regex (email will be constructed as `name@domain`)
22
// name parts can be alnum + some special characters
3-
const namePartSubRegexStr = '[a-zA-Z0-9!#$%&\'*+/=?^_`{|}~-]+';
3+
const namePartSubRegexStr = "[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+";
44
// name is 1+ name parts joined by periods (no leading or dangling period, no consecutive periods)
55
const nameSubRegexStr = `${namePartSubRegexStr}(?:\\.${namePartSubRegexStr})*`;
66
// domain parts can be alnum and dash characters (no leading and dangling dashes, max 63 chars long)
@@ -79,7 +79,8 @@ export const GITHUB_REGEX = new RegExp(`^${GITHUB_REGEX_STR}$`, 'i');
7979
* For matching linkedin URLs for both profiles and companies.
8080
* Used for validating urls in user settings.
8181
*/
82-
export const LINKEDIN_PROFILE_REGEX = /^(https?:\/\/)?(www\.)?([a-z]{2}\.)?linkedin\.com\/(in|company)\/((?:[A-Za-z0-9_-]|%[0-9A-Fa-f]{2})+)\/?$/;
82+
export const LINKEDIN_PROFILE_REGEX =
83+
/^(https?:\/\/)?(www\.)?([a-z]{2}\.)?linkedin\.com\/(in|company)\/((?:[A-Za-z0-9_-]|%[0-9A-Fa-f]{2})+)\/?$/;
8384

8485
/**
8586
* @deprecated Discontinue usage of this regexps, in favor of HTTP_URL_REGEX
@@ -89,51 +90,55 @@ export const URL_REGEX = /^https?:\/\//i;
8990
// Inspired by https://gist.github.com/dperini/729294, but doesn't match FTP URLs
9091
export const HTTP_URL_REGEX = new RegExp(
9192
'^' +
92-
// protocol identifier (optional)
93-
// short syntax // still required
94-
// NOTE: We removed "|ftp"
95-
'(?:(?:(?:https?):)?\\/\\/)' +
96-
// user:pass BasicAuth (optional)
97-
'(?:\\S+(?::\\S*)?@)?' +
98-
'(?:' +
99-
// IP address exclusion
100-
// private & local networks
101-
'(?!(?:10|127)(?:\\.\\d{1,3}){3})' +
102-
'(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})' +
103-
'(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})' +
104-
// IP address dotted notation octets
105-
// excludes loopback network 0.0.0.0
106-
// excludes reserved space >= 224.0.0.0
107-
// excludes network & broadcast addresses
108-
// (first & last IP address of each class)
109-
'(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])' +
110-
'(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}' +
111-
'(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))' +
112-
'|' +
113-
// host & domain names, may end with dot
114-
// can be replaced by a shortest alternative
115-
// (?![-_])(?:[-\\w\\u00a1-\\uffff]{0,63}[^-_]\\.)+
116-
'(?:' +
117-
'(?:' +
118-
'[a-z0-9\\u00a1-\\uffff]' +
119-
'[a-z0-9\\u00a1-\\uffff_-]{0,62}' +
120-
')?' +
121-
'[a-z0-9\\u00a1-\\uffff]\\.' +
122-
')+' +
123-
// TLD identifier name, may end with dot
124-
// NOTE: "|xn--[a-z0-9]+" is our addition to support IDNs like "http://xn--80aaxitdbjk.xn--p1ai",
125-
// they can be used in a browser, so we consider them valid
126-
'(?:[a-z\\u00a1-\\uffff]{2,}\\.?|xn--[a-z0-9]+)' +
127-
')' +
128-
// port number (optional)
129-
'(?::\\d{2,5})?' +
130-
// resource path (optional)
131-
'(?:[/?#]\\S*)?' +
132-
'$', 'i',
93+
// protocol identifier (optional)
94+
// short syntax // still required
95+
// NOTE: We removed "|ftp"
96+
'(?:(?:(?:https?):)?\\/\\/)' +
97+
// user:pass BasicAuth (optional)
98+
'(?:\\S+(?::\\S*)?@)?' +
99+
'(?:' +
100+
// IP address exclusion
101+
// private & local networks
102+
'(?!(?:10|127)(?:\\.\\d{1,3}){3})' +
103+
'(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})' +
104+
'(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})' +
105+
// IP address dotted notation octets
106+
// excludes loopback network 0.0.0.0
107+
// excludes reserved space >= 224.0.0.0
108+
// excludes network & broadcast addresses
109+
// (first & last IP address of each class)
110+
'(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])' +
111+
'(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}' +
112+
'(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))' +
113+
'|' +
114+
// host & domain names, may end with dot
115+
// can be replaced by a shortest alternative
116+
// (?![-_])(?:[-\\w\\u00a1-\\uffff]{0,63}[^-_]\\.)+
117+
'(?:' +
118+
'(?:' +
119+
'[a-z0-9\\u00a1-\\uffff]' +
120+
'[a-z0-9\\u00a1-\\uffff_-]{0,62}' +
121+
')?' +
122+
'[a-z0-9\\u00a1-\\uffff]\\.' +
123+
')+' +
124+
// TLD identifier name, may end with dot
125+
// NOTE: "|xn--[a-z0-9]+" is our addition to support IDNs like "http://xn--80aaxitdbjk.xn--p1ai",
126+
// they can be used in a browser, so we consider them valid
127+
'(?:[a-z\\u00a1-\\uffff]{2,}\\.?|xn--[a-z0-9]+)' +
128+
')' +
129+
// port number (optional)
130+
'(?::\\d{2,5})?' +
131+
// resource path (optional)
132+
'(?:[/?#]\\S*)?' +
133+
'$',
134+
'i',
133135
);
134136

135137
// E.g. https://gist.github.com/jancurn/2dbe83fea77c439b1119fb3f118513e7
136-
export const GITHUB_GIST_URL_REGEX = new RegExp(`^https:\\/\\/gist\\.github\\.com\\/${GITHUB_REGEX_STR}\\/[0-9a-f]{32}$`, 'i');
138+
export const GITHUB_GIST_URL_REGEX = new RegExp(
139+
`^https:\\/\\/gist\\.github\\.com\\/${GITHUB_REGEX_STR}\\/[0-9a-f]{32}$`,
140+
'i',
141+
);
137142

138143
/**
139144
* Split's path /aaa/bbb/ccc into an array ['aaa', 'bbb', 'ccc].

packages/datastructures/src/linked_list.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/*!
32
* This module defines the LinkedList class, which represents a doubly-linked list data structure.
43
*
@@ -12,7 +11,7 @@
1211
* The function attempts to do so using data1's function 'equal(data)' if there is one,
1312
* otherwise it uses '==' operator.
1413
*/
15-
const dataEqual = <T> (data1: T, data2: T): boolean => {
14+
const dataEqual = <T>(data1: T, data2: T): boolean => {
1615
if (data1 === null) return data2 === null;
1716
if ((data1 as any).equals) return (data1 as any).equals(data2);
1817

@@ -40,8 +39,8 @@ export class LinkedList<T = any> {
4039
length = 0;
4140

4241
/**
43-
* Appends a new node with specific data to the end of the linked list.
44-
*/
42+
* Appends a new node with specific data to the end of the linked list.
43+
*/
4544
add(data: T, toFirstPosition?: boolean): LinkedListNode<T> {
4645
const node = new LinkedListNode(data);
4746
this.addNode(node, toFirstPosition);
@@ -67,7 +66,8 @@ export class LinkedList<T = any> {
6766
node.next = this.head;
6867
this.head!.prev = node;
6968
this.head = node;
70-
} else { // last position
69+
} else {
70+
// last position
7171
node.prev = this.tail;
7272
this.tail!.next = node;
7373
this.tail = node;

0 commit comments

Comments
 (0)