Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup #329

Merged
merged 4 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"rimraf": "^3.0.2",
"stats-lite": "^2.2.0",
"ts-node": "^10.8.2",
"typescript": "~5.4.5"
"typescript": "~5.5.4"
},
"dependencies": {
"@graphql-tools/schema": "^8.5.0",
Expand Down
2 changes: 1 addition & 1 deletion spec/model/implementation/i18n-fields.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const FULLY = 'fully';
const PARTIALLY = 'partially';
const NAMESPACED = 'namespaced';

const i18n: LocalizationConfig[] = [
const i18n: ReadonlyArray<LocalizationConfig> = [
{
language: FULLY,
namespacePath: [],
Expand Down
2 changes: 1 addition & 1 deletion spec/model/implementation/i18n-types.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const FULLY = 'fully';
const PARTIALLY = 'partially';
const NAMESPACED = 'namespaced';

const i18n: LocalizationConfig[] = [
const i18n: ReadonlyArray<LocalizationConfig> = [
{
language: FULLY,
namespacePath: [],
Expand Down
2 changes: 1 addition & 1 deletion spec/performance/associations.perf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function testFetchWithAssociations(config: {
associationCount: number;
}): BenchmarkConfig {
let env: TestEnvironment;
let sampledIDs: string[] = [];
let sampledIDs: ReadonlyArray<string> = [];
return {
name: `Fetch one of one root entity with one level deep associations (${config.paperCount} papers, ${config.userCount} users, ${config.associationCount} associations`,
async beforeAll() {
Expand Down
2 changes: 1 addition & 1 deletion spec/performance/crud.perf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function getOneOfXRootEntities(config: {
onlyFewFields?: boolean;
}): BenchmarkConfig {
let env: TestEnvironment;
let sampledIDs: string[] = [];
let sampledIDs: ReadonlyArray<string> = [];
const sizeFactor = getSizeFactorForJSONLength(config.documentLength);
return {
name: `Get ${config.onlyFewFields ? 'two fields of ' : ''} one of ${
Expand Down
2 changes: 1 addition & 1 deletion spec/performance/query-pipeline.perf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function testQueryPipeline(params: {

let schema: GraphQLSchema;
let model: Model;
let preparedQueries: PreparedQuery[];
let preparedQueries: ReadonlyArray<PreparedQuery>;

return {
name: `Run query pipeline with ${optionsStr}`,
Expand Down
2 changes: 1 addition & 1 deletion spec/performance/references.perf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function testReferenceLookup(config: {
referenceCountEach: number;
}): BenchmarkConfig {
let env: TestEnvironment;
let sampledIDs: string[] = [];
let sampledIDs: ReadonlyArray<string> = [];
return {
name: `Set up ${config.paperCount} root entities with ${config.referenceCountEach} references each, then fetch a random root entity with all its references`,
async beforeAll() {
Expand Down
18 changes: 12 additions & 6 deletions spec/performance/support/async-bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export interface BenchmarkResultConfig {

readonly elapsedTime: number;
readonly setUpTime: number;
readonly cycleDetails: BenchmarkCycleDetails[];
readonly cycleDetails: ReadonlyArray<BenchmarkCycleDetails>;
}

export class BenchmarkResult {
Expand All @@ -100,7 +100,7 @@ export class BenchmarkResult {
/**
* Detailed information about each cycle
*/
public readonly cycleDetails: BenchmarkCycleDetails[];
public readonly cycleDetails: ReadonlyArray<BenchmarkCycleDetails>;

/**
* The mean time, in seconds, per iteration
Expand Down Expand Up @@ -154,7 +154,9 @@ export async function benchmark(
config: BenchmarkConfig,
callbacks?: BenchmarkExecutionCallbacks,
): Promise<BenchmarkResult> {
async function cycle(count: number): Promise<{ times: number[]; netTime: number }> {
async function cycle(
count: number,
): Promise<{ times: ReadonlyArray<number>; netTime: number }> {
if (config.before) {
await config.before({ count });
}
Expand All @@ -171,7 +173,9 @@ export async function benchmark(
};
}

async function cycleSync(count: number): Promise<{ times: number[]; netTime: number }> {
async function cycleSync(
count: number,
): Promise<{ times: ReadonlyArray<number>; netTime: number }> {
if (config.before) {
await config.before({ count });
}
Expand All @@ -188,7 +192,9 @@ export async function benchmark(
};
}

async function cycleDetailed(count: number): Promise<{ times: number[]; netTime: number }> {
async function cycleDetailed(
count: number,
): Promise<{ times: ReadonlyArray<number>; netTime: number }> {
if (config.before) {
await config.before({ count });
}
Expand Down Expand Up @@ -359,7 +365,7 @@ const tTable: { [key: string]: number } = {
infinity: 1.96,
};

function getTimings(times: number[]): Timings {
function getTimings(times: ReadonlyArray<number>): Timings {
const mean: number = stats.mean(times);
// Compute the sample standard deviation (estimate of the population standard deviation).
const sd = stats.stdev(times);
Expand Down
5 changes: 3 additions & 2 deletions spec/performance/support/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { Log4jsLoggerProvider } from '../../helpers/log4js-logger-provider';
import { createTempDatabase } from '../../regression/initialization';

// arangojs typings for this are completely broken
export const aql: (template: TemplateStringsArray, ...args: any[]) => any = require('arangojs').aql;
export const aql: (template: TemplateStringsArray, ...args: ReadonlyArray<any>) => any =
require('arangojs').aql;

const MODEL_PATH = resolve(__dirname, '../../regression/papers/model');

Expand Down Expand Up @@ -130,7 +131,7 @@ export async function addNumberedPapersWithAQL(environment: TestEnvironment, cou
export async function getRandomPaperIDsWithAQL(
environment: TestEnvironment,
count: number,
): Promise<string[]> {
): Promise<ReadonlyArray<string>> {
const cursor = await environment
.getDB()
.query(aql`FOR node IN papers SORT RAND() LIMIT ${count} RETURN { id: node._key }`);
Expand Down
6 changes: 3 additions & 3 deletions spec/regression/initialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function createTempDatabase(): Promise<ArangoDBConfig> {
const dbs = await systemDatabase.listDatabases();
if (dbs.indexOf(DATABASE_NAME) >= 0) {
const db = systemDatabase.database(DATABASE_NAME);
const colls = (await db.collections(true)) as Collection[];
const colls = await db.collections(true);
await Promise.all(colls.map((coll) => coll.drop()));
} else {
await systemDatabase.createDatabase(DATABASE_NAME);
Expand Down Expand Up @@ -144,7 +144,7 @@ export async function initTestData(
return { fillTemplateStrings };
}

function wrapNamespaceForQuery(stuff: string, namespace: string[]) {
function wrapNamespaceForQuery(stuff: string, namespace: ReadonlyArray<string>) {
if (!namespace) {
return stuff;
}
Expand All @@ -155,7 +155,7 @@ function wrapNamespaceForQuery(stuff: string, namespace: string[]) {
return result;
}

function retrieveIdFromResult(result: ExecutionResult, namespace: string[]) {
function retrieveIdFromResult(result: ExecutionResult, namespace: ReadonlyArray<string>) {
const ns = [...namespace];
let node = result.data as any;
while (ns.length) {
Expand Down
2 changes: 1 addition & 1 deletion spec/regression/regression-suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class RegressionSuite {

const operations = parse(gqlSource).definitions.filter(
(def) => def.kind == 'OperationDefinition',
) as OperationDefinitionNode[];
) as ReadonlyArray<OperationDefinitionNode>;
this._isSetUpClean =
this._isSetUpClean && !operations.some((op) => op.operation == 'mutation');
const hasNamedOperations = operations.length && operations[0].name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const invalidValueWithComments = `{
describe('sidecar-schema validator', () => {
const validator = new SidecarSchemaValidator();

function getValidatorMessages(ps: ProjectSource): ValidationMessage[] {
function getValidatorMessages(ps: ProjectSource): ReadonlyArray<ValidationMessage> {
const parsedSource = parseProjectSource(ps, {}, new ValidationContext());
if (parsedSource) {
return validator.validate(parsedSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ValidationContext, ValidationMessage } from '../../../src/model/validat
import { ProjectSource } from '../../../src/project/source';
import { parseProjectSource } from '../../../src/schema/schema-builder';

export function getMessages(source: ProjectSource): ValidationMessage[] {
export function getMessages(source: ProjectSource): ReadonlyArray<ValidationMessage> {
const validationContext = new ValidationContext();
parseProjectSource(source, {}, validationContext);

Expand Down
2 changes: 1 addition & 1 deletion src/authorization/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { AuthContext } from './auth-basics';
import { moveErrorsToOutputNodes } from './move-errors-to-output-nodes';
import { transformNode } from './transformers';

const MUTATIONS: Function[] = [
const MUTATIONS: ReadonlyArray<Function> = [
CreateEntityQueryNode,
UpdateEntitiesQueryNode,
DeleteEntitiesQueryNode,
Expand Down
3 changes: 2 additions & 1 deletion src/authorization/permission-descriptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { simplifyBooleans } from '../query-tree/utils';
import { createFieldPathNode } from '../schema-generation/field-path-node';
import { ACCESS_GROUP_FIELD } from '../schema/constants';
import { AccessOperation, AuthContext } from './auth-basics';
import { isReadonlyArray } from '../utils/utils';

export enum ConditionExplanationContext {
BEFORE_WRITE,
Expand Down Expand Up @@ -248,7 +249,7 @@ export class ProfileBasedPermissionDescriptor extends PermissionDescriptor {

if (restriction.claim !== undefined) {
const claimValue = authContext.claims?.[restriction.claim];
const claimValues = Array.isArray(claimValue) ? claimValue : [claimValue];
const claimValues = isReadonlyArray(claimValue) ? claimValue : [claimValue];
const sanitizedClaimValues = claimValues.filter(
(v) => !!v && typeof v === 'string',
);
Expand Down
2 changes: 1 addition & 1 deletion src/config/parsed-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PlainObject } from '../utils/utils';
import { MessageLocation } from '../model/validation/message';

export interface ParsedProject {
readonly sources: ParsedProjectSource[];
readonly sources: ReadonlyArray<ParsedProjectSource>;
}

export type ParsedProjectSource = ParsedGraphQLProjectSource | ParsedObjectProjectSource;
Expand Down
6 changes: 3 additions & 3 deletions src/database/arangodb/aql-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ import {
import { Quantifier, QuantifierFilterNode } from '../../query-tree/quantifiers';
import { extractVariableAssignments, simplifyBooleans } from '../../query-tree/utils';
import { not } from '../../schema-generation/utils/input-types';
import { Constructor, decapitalize } from '../../utils/utils';
import { Constructor, decapitalize, isReadonlyArray } from '../../utils/utils';
import { FlexSearchTokenizable } from '../database-adapter';
import { analyzeLikePatternPrefix } from '../like-helpers';
import {
Expand Down Expand Up @@ -286,7 +286,7 @@ class QueryContext {
return variable;
}

getPreExecuteQueries(): AQLCompoundQuery[] {
getPreExecuteQueries(): ReadonlyArray<AQLCompoundQuery> {
return this.preExecQueries;
}

Expand Down Expand Up @@ -1862,7 +1862,7 @@ function getFullIDsFromKeysNode(
}
if (
idsNode instanceof LiteralQueryNode &&
Array.isArray(idsNode.value) &&
isReadonlyArray(idsNode.value) &&
idsNode.value.every((v) => typeof v === 'string')
) {
const collName = getCollectionNameForRootEntity(rootEntityType);
Expand Down
15 changes: 9 additions & 6 deletions src/database/arangodb/aql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function indentLineBreaks(val: string, level: number) {
}

export class AQLCodeBuildingContext {
private readonly boundValues: any[] = [];
private readonly boundValues: unknown[] = [];
private readonly boundCollectionNames = new Set<string>();
private variableBindings = new Map<AQLVariable, string>();
private preExecInjectedVariablesMap = new Map<AQLQueryResultVariable, string>();
Expand Down Expand Up @@ -340,7 +340,10 @@ export namespace aql {
return new AQLCompoundFragment(fragments);
}

export function join(fragments: AQLFragment[], separator: AQLFragment): AQLFragment {
export function join(
fragments: ReadonlyArray<AQLFragment>,
separator: AQLFragment,
): AQLFragment {
const newFragments: AQLFragment[] = [];
let isFirst = true;
for (const fragment of fragments) {
Expand All @@ -360,7 +363,7 @@ export namespace aql {
return new AQLCodeFragment(code);
}

export function lines(...fragments: AQLFragment[]) {
export function lines(...fragments: ReadonlyArray<AQLFragment>) {
return join(fragments, aql`\n`);
}

Expand Down Expand Up @@ -424,7 +427,7 @@ export namespace aql {
*/
export class AQLCompoundQuery extends AQLFragment {
constructor(
public readonly preExecQueries: AQLCompoundQuery[],
public readonly preExecQueries: ReadonlyArray<AQLCompoundQuery>,
public readonly aqlQuery: AQLFragment,
public readonly resultVar: AQLQueryResultVariable | undefined,
public readonly resultValidator: QueryResultValidator | undefined,
Expand All @@ -439,14 +442,14 @@ export class AQLCompoundQuery extends AQLFragment {
*
* The returned transaction steps are to be executed sequentially.
*/
getExecutableQueries(): AQLExecutableQuery[] {
getExecutableQueries(): ReadonlyArray<AQLExecutableQuery> {
const resultVarToNameMap = new Map<AQLQueryResultVariable, string>();
return this.getExecutableQueriesRecursive(resultVarToNameMap);
}

private getExecutableQueriesRecursive(
resultVarToNameMap: Map<AQLQueryResultVariable, string>,
): AQLExecutableQuery[] {
): ReadonlyArray<AQLExecutableQuery> {
const executableQueries = flatMap(this.preExecQueries, (aqlQuery) =>
aqlQuery.getExecutableQueriesRecursive(resultVarToNameMap),
);
Expand Down
2 changes: 1 addition & 1 deletion src/database/arangodb/arangodb-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ export class ArangoDBAdapter implements DatabaseAdapter {
async executeExt({ queryTree, ...options }: ExecutionArgs): Promise<ExecutionResult> {
const prepStartTime = getPreciseTime();
globalContext.registerContext(this.schemaContext);
let executableQueries: AQLExecutableQuery[];
let executableQueries: ReadonlyArray<AQLExecutableQuery>;
let aqlQuery: AQLCompoundQuery;
const oldEnableIndentationForCode = aqlConfig.enableIndentationForCode;
aqlConfig.enableIndentationForCode = !!options.recordPlan;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { normalizeUrl } from 'arangojs/lib/normalizeUrl';
import { ArangojsResponse } from 'arangojs/lib/request';
import { RequestInstrumentation, requestInstrumentationBodyKey } from './config';
import { createRequest, RequestOptions as CustomRequestOptions } from './custom-request';
import { isReadonlyArray } from '../../../utils/utils';

/**
* @internal
Expand Down Expand Up @@ -111,8 +112,8 @@ export class CustomConnection extends Connection {
});
}

addToHostList(urls: string | string[]): string[] {
const cleanUrls = (Array.isArray(urls) ? urls : [urls]).map((url) => normalizeUrl(url));
addToHostList(urls: string | ReadonlyArray<string>): string[] {
const cleanUrls = (isReadonlyArray(urls) ? urls : [urls]).map((url) => normalizeUrl(url));
const newUrls = cleanUrls.filter((url) => this._hostUrls.indexOf(url) === -1);
this._hostUrls.push(...newUrls);
this._hosts.push(
Expand Down
Loading
Loading