Skip to content

Commit

Permalink
fix(in-app-onboarding): do not force skipLibCheck on customers TS con…
Browse files Browse the repository at this point in the history
…figuration (#680)
  • Loading branch information
romain-gilliotte authored May 3, 2023
1 parent b6ce451 commit c374117
Show file tree
Hide file tree
Showing 18 changed files with 130 additions and 245 deletions.
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
"markdown-link-check": "^3.10.3",
"multi-semantic-release": "^3.0.1",
"nock": "^13.3.0",
"patch-package": "^6.5.1",
"postinstall-postinstall": "^2.1.0",
"prettier": "^2.8.2",
"prettier-eslint": "^15.0.1",
"semantic-release-slack-bot": "^3.5.3",
Expand All @@ -44,7 +42,6 @@
"lint": "lerna exec --parallel eslint src test",
"lint:fix": "lerna exec eslint src test -- --fix",
"prepare": "husky install",
"postinstall": "patch-package",
"test": "jest",
"test:coverage": "yarn test --coverage"
},
Expand Down
5 changes: 3 additions & 2 deletions packages/agent/src/services/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import JsonApiSerializer from 'json-api-serializer';
import path from 'path';

import { JsonApiRelationshipOptionsExt } from './type-overrides';
import IdUtils from '../utils/id';

type SerializedRecord = { forestId: string };
Expand Down Expand Up @@ -104,8 +105,8 @@ export default class Serializer {

private buildRelationshipsConfiguration(
collection: Collection,
): Record<string, JsonApiSerializer.RelationshipOptions> {
const relationships: Record<string, JsonApiSerializer.RelationshipOptions> = {};
): Record<string, JsonApiRelationshipOptionsExt> {
const relationships: Record<string, JsonApiRelationshipOptionsExt> = {};
const urlPrefix = path.posix.join('/forest', collection.name);

for (const [name, field] of Object.entries(collection.schema.fields)) {
Expand Down
9 changes: 9 additions & 0 deletions packages/agent/src/services/type-overrides.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import JSONAPISerializer from 'json-api-serializer';

export interface JsonApiRelationshipOptionsExt extends JSONAPISerializer.RelationshipOptions {
deserialize?: (data: Record<string, unknown>) => unknown;
}

export interface JsonApiOptionsExt extends JSONAPISerializer.Options {
relationships: Record<string, JsonApiRelationshipOptionsExt>;
}
24 changes: 24 additions & 0 deletions packages/datasource-sequelize/src/type-overrides.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Override the types from sequelize to add properties from private fields and methods
// that we use in the datasource-sequelize package, but that are not exported by sequelize.

import {
AbstractDataType,
AbstractDataTypeConstructor,
ArrayDataType,
BelongsToMany,
Model,
ModelAttributeColumnOptions,
} from 'sequelize';

export interface BelongsToManyExt extends BelongsToMany {
through: { model: typeof Model };
}

export interface ModelAttributeColumnOptionsExt extends ModelAttributeColumnOptions {
_autoGenerated?: boolean;
}

export interface ArrayDataTypeExt<T extends AbstractDataTypeConstructor | AbstractDataType>
extends ArrayDataType<T> {
type: AbstractDataType;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import {
HasMany,
HasOne,
Model,
ModelAttributeColumnOptions,
ModelAttributes,
ModelDefined,
} from 'sequelize';

import TypeConverter from './type-converter';
import { BelongsToManyExt, ModelAttributeColumnOptionsExt } from '../type-overrides';

export default class ModelToCollectionSchemaConverter {
private static convertAssociation(
Expand All @@ -37,7 +37,7 @@ export default class ModelToCollectionSchemaConverter {
case BelongsToMany.name:
return {
foreignCollection: association.target.name,
throughCollection: (association as BelongsToMany).through.model.name,
throughCollection: (association as BelongsToManyExt).through.model.name,
originKey: (association as BelongsToMany).foreignKey,
originKeyTarget: (association as BelongsToMany).sourceKey,
foreignKey: (association as BelongsToMany).otherKey,
Expand Down Expand Up @@ -86,7 +86,7 @@ export default class ModelToCollectionSchemaConverter {
return schemaAssociations;
}

private static convertAttribute(attribute: ModelAttributeColumnOptions): FieldSchema {
private static convertAttribute(attribute: ModelAttributeColumnOptionsExt): FieldSchema {
const sequelizeColumnType = attribute.type as AbstractDataType;
const columnType = TypeConverter.fromDataType(sequelizeColumnType);
const filterOperators = TypeConverter.operatorsForColumnType(columnType);
Expand Down Expand Up @@ -138,7 +138,7 @@ export default class ModelToCollectionSchemaConverter {

Object.entries(attributes).forEach(([name, attribute]) => {
try {
fields[name] = this.convertAttribute(attribute as ModelAttributeColumnOptions);
fields[name] = this.convertAttribute(attribute as ModelAttributeColumnOptionsExt);
} catch (error) {
logger?.('Warn', `Skipping column '${modelName}.${name}' (${error.message})`);
}
Expand Down
6 changes: 4 additions & 2 deletions packages/datasource-sequelize/src/utils/type-converter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ColumnType, Operator, PrimitiveTypes } from '@forestadmin/datasource-toolkit';
import { AbstractDataType, AbstractDataTypeConstructor, ArrayDataType, DataTypes } from 'sequelize';
import { AbstractDataType, AbstractDataTypeConstructor, DataTypes } from 'sequelize';

import { ArrayDataTypeExt } from '../type-overrides';

export default class TypeConverter {
private static getColumnTypeFromDataType(dataType: AbstractDataType): PrimitiveTypes {
Expand Down Expand Up @@ -50,7 +52,7 @@ export default class TypeConverter {

public static fromDataType(dataType: AbstractDataType): ColumnType {
if (dataType.key === DataTypes.ARRAY.key) {
const arrayDataType = dataType as ArrayDataType<AbstractDataTypeConstructor>;
const arrayDataType = dataType as ArrayDataTypeExt<AbstractDataTypeConstructor>;

return [TypeConverter.fromDataType(arrayDataType.type as unknown as AbstractDataType)];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ColumnDescription, QueryTypes, Sequelize } from 'sequelize';
import { QueryTypes, Sequelize } from 'sequelize';

import { SequelizeColumn } from '../type-overrides';
import { ColumnType, ScalarSubType } from '../types';

export default class SqlTypeConverter {
Expand All @@ -13,7 +14,7 @@ export default class SqlTypeConverter {
async convert(
tableName: string,
columnName: string,
columnInfo: ColumnDescription,
columnInfo: SequelizeColumn,
): Promise<ColumnType> {
switch (columnInfo.type) {
case 'ARRAY':
Expand All @@ -29,7 +30,7 @@ export default class SqlTypeConverter {
}

/** Get the type of an enum from sequelize column description */
private getEnumType(columnInfo: ColumnDescription): ColumnType {
private getEnumType(columnInfo: SequelizeColumn): ColumnType {
if (columnInfo.type === 'USER-DEFINED') {
// Postgres enum
return columnInfo?.special?.length > 0
Expand Down
10 changes: 6 additions & 4 deletions packages/datasource-sql/src/introspection/introspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { Dialect, Sequelize } from 'sequelize';

import DefaultValueParser from './helpers/default-value-parser';
import SqlTypeConverter from './helpers/sql-type-converter';
import { SequelizeColumn, SequelizeReference, Table } from './types';
import { QueryInterfaceExt, SequelizeColumn, SequelizeReference } from './type-overrides';
import { Table } from './types';

export default class Introspector {
static async introspect(sequelize: Sequelize, logger?: Logger): Promise<Table[]> {
Expand Down Expand Up @@ -36,10 +37,11 @@ export default class Introspector {
tableName: string,
): Promise<Table> {
// Load columns descriptions, indexes and references of the current table.
const queryInterface = sequelize.getQueryInterface() as QueryInterfaceExt;
const [columnDescriptions, tableIndexes, tableReferences] = await Promise.all([
sequelize.getQueryInterface().describeTable(tableName),
sequelize.getQueryInterface().showIndex(tableName),
sequelize.getQueryInterface().getForeignKeyReferencesForTable(tableName),
queryInterface.describeTable(tableName),
queryInterface.showIndex(tableName),
queryInterface.getForeignKeyReferencesForTable(tableName),
]);

// Create columns
Expand Down
56 changes: 56 additions & 0 deletions packages/datasource-sql/src/introspection/type-overrides.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Override the types from sequelize to add properties from private fields and methods
// that we use in the datasource-sequelize package, but that are not exported by sequelize.

import {
AbstractDataType,
AbstractDataTypeConstructor,
ColumnDescription,
Logging,
QueryInterface,
QueryInterfaceOptions,
QueryOptions,
TableName,
} from 'sequelize/types';

export interface SequelizeIndex {
name: string;
primary: boolean;
unique: boolean;
indkey: string;
definition: string;
fields: { attribute: string }[];
}

export interface SequelizeColumn extends ColumnDescription {
special?: string[];
}

export type SequelizeColumnType = AbstractDataType | AbstractDataTypeConstructor;

export type SequelizeReference = {
constraintName: string;
constraintSchema: string;
constraintCatalog: string;
tableName: string;
tableSchema: string;
tableCatalog: string;
columnName: string;
referencedTableSchema: string;
referencedTableCatalog: string;
referencedTableName: string;
referencedColumnName: string;
};

export interface QueryInterfaceExt extends QueryInterface {
showIndex(tableName: string | object, options?: QueryOptions): Promise<SequelizeIndex[]>;

getForeignKeyReferencesForTable(
tableName: TableName,
options?: QueryInterfaceOptions,
): Promise<SequelizeReference[]>;

describeTable(
tableName: TableName,
options?: string | ({ schema?: string; schemaDelimiter?: string } & Logging),
): Promise<Record<string, SequelizeColumn>>;
}
8 changes: 0 additions & 8 deletions packages/datasource-sql/src/introspection/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
import { AbstractDataType, AbstractDataTypeConstructor, QueryInterface } from 'sequelize/types';

export type SequelizeColumn = Awaited<ReturnType<QueryInterface['describeTable']>>[number];
export type SequelizeColumnType = AbstractDataType | AbstractDataTypeConstructor;
export type SequelizeReference = Awaited<
ReturnType<QueryInterface['getForeignKeyReferencesForTable']>
>[number];

export type ScalarSubType =
| 'BIGINT'
| 'BLOB'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
/* eslint-disable max-classes-per-file */
import { DataTypes } from 'sequelize';

import { ColumnType, SequelizeColumnType } from '../../introspection/types';
import { SequelizeColumnType } from '../../introspection/type-overrides';
import { ColumnType } from '../../introspection/types';

export default class SequelizeTypeFactory {
static makeType(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ColumnDescription, DataTypes, Sequelize } from 'sequelize';
import { DataTypes, Sequelize } from 'sequelize';

import SqlTypeConverter from '../../../src/introspection/helpers/sql-type-converter';
import { SequelizeColumn } from '../../../src/introspection/type-overrides';

const makeColumnDescription = (description: Partial<ColumnDescription>) => {
const makeColumnDescription = (description: Partial<SequelizeColumn>) => {
return {
type: 'THIS-SHOULD-NEVER-MATCH',
allowNull: false,
Expand All @@ -14,11 +15,11 @@ const makeColumnDescription = (description: Partial<ColumnDescription>) => {
};
};

const makeColumnDescriptionForType = (type: string): ColumnDescription => {
const makeColumnDescriptionForType = (type: string): SequelizeColumn => {
return makeColumnDescription({ type });
};

const makeColumnDescriptionForEnum = (enumValues: Array<string>): ColumnDescription => {
const makeColumnDescriptionForEnum = (enumValues: Array<string>): SequelizeColumn => {
return makeColumnDescription({ type: 'USER-DEFINED', special: enumValues });
};

Expand Down
5 changes: 4 additions & 1 deletion packages/forestadmin-client/src/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Client, ClientAuthMethod, Issuer, IssuerMetadata } from 'openid-client';

import { ClientExt } from './type-overrides';
import { UserInfo } from './types';
import { ForestAdminClientOptionsWithDefaults } from '../types';
import ServerUtils from '../utils/server';
Expand All @@ -14,7 +15,9 @@ export default class AuthService {
const issuer = new Issuer(config);
const registration = { token_endpoint_auth_method: 'none' as ClientAuthMethod };

return issuer.Client.register(registration, { initialAccessToken: this.options.envSecret });
return (issuer.Client as ClientExt).register(registration, {
initialAccessToken: this.options.envSecret,
});
}

async getUserInfo(renderingId: number, accessToken: string): Promise<UserInfo> {
Expand Down
5 changes: 5 additions & 0 deletions packages/forestadmin-client/src/auth/type-overrides.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { BaseClient, ClientOptions, RegisterOther, TypeOfGenericClient } from 'openid-client';

export interface ClientExt extends TypeOfGenericClient<BaseClient> {
register: (metadata: object, other?: RegisterOther & ClientOptions) => Promise<BaseClient>;
}
12 changes: 0 additions & 12 deletions patches/@types+json-api-serializer+2.6.3.patch

This file was deleted.

12 changes: 0 additions & 12 deletions patches/openid-client+5.3.1.patch

This file was deleted.

Loading

0 comments on commit c374117

Please sign in to comment.