Skip to content

Commit

Permalink
feat(esm): moving annotations api to esm
Browse files Browse the repository at this point in the history
  • Loading branch information
bassrock committed Jan 7, 2025
1 parent cb9a134 commit f7d2ef7
Show file tree
Hide file tree
Showing 44 changed files with 230 additions and 180 deletions.
27 changes: 27 additions & 0 deletions packages/tsconfig/graphql-esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"target": "ES2024",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"allowImportingTsExtensions": true,
"rewriteRelativeImportExtensions": true,
"lib": [
"es2019",
"es2020.bigint",
"es2020.string",
"es2020.symbol.wellknown"
],
"removeComments": true,
"esModuleInterop": true,
"noEmitOnError": false,
"sourceMap": true,
"inlineSources": true,
"sourceRoot": "/",
"declaration": true,
"noEmitHelpers": true,
"importHelpers": true
}
}
9 changes: 0 additions & 9 deletions servers/annotations-api/jest.config.js

This file was deleted.

26 changes: 26 additions & 0 deletions servers/annotations-api/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { Config } from 'jest';

const config: Config = {
preset: 'ts-jest/presets/default-esm', // or other ESM presets
testEnvironment: 'node',
testMatch: ['**/?(*.)+(spec|integration).ts'],
testPathIgnorePatterns: ['/dist/'],
setupFiles: ['./jest.setup.ts'],
displayName: 'annotations-api',
setupFilesAfterEnv: ['jest-extended/all'],
moduleNameMapper: {
"^(\\.{1,2}/.*)\\.js$": "$1"
},
transform: {
['^.+.tsx?$']: [
'ts-jest',
{
tsconfig: '<rootDir>/tsconfig.json',
isolatedModules: true,
useESM: true,
},
],
}
};

export default config;
File renamed without changes.
1 change: 1 addition & 0 deletions servers/annotations-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "",
"license": "ISC",
"author": "",
"type": "module",
"main": "dist/main.js",
"files": [
"dist",
Expand Down
2 changes: 1 addition & 1 deletion servers/annotations-api/src/database/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import knex, { Knex } from 'knex';
import config from '../config';
import config from '../config/index.ts';
import { DynamoDBClient, DynamoDBClientConfig } from '@aws-sdk/client-dynamodb';

let readDb: Knex;
Expand Down
6 changes: 3 additions & 3 deletions servers/annotations-api/src/dataservices/dataloaders.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NotesDataService } from '../dataservices/notes';
import { dynamoClient } from '../database/client';
import { createNotesLoader, orderAndMapNotes } from './dataloaders';
import { NotesDataService } from '../dataservices/notes.ts';
import { dynamoClient } from '../database/client.ts';
import { createNotesLoader, orderAndMapNotes } from './dataloaders.ts';

describe('dataloaders', () => {
const mockNotesResponse = [
Expand Down
4 changes: 2 additions & 2 deletions servers/annotations-api/src/dataservices/dataloaders.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import DataLoader from 'dataloader';
import { HighlightNote } from '../types';
import { NotesDataService } from './notes';
import { HighlightNote } from '../types.ts';
import { NotesDataService } from './notes.ts';

/**
* Function for initializing dataloader. This function should be
Expand Down
16 changes: 8 additions & 8 deletions servers/annotations-api/src/dataservices/highlights.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Knex } from 'knex';
import { IContext } from '../server/apollo/context';
import { HighlightEntity } from '../types';
import { IContext } from '../server/apollo/context.ts';
import { HighlightEntity } from '../types.ts';
import { NotFoundError, UserInputError } from '@pocket-tools/apollo-utils';
import { v4 as uuid } from 'uuid';
import config from '../config';
import { groupByCount, sumByKey } from '../utils/dataAggregation';
import { UsersMeta } from './usersMeta';
import { SavedItem } from './savedItem';
import { failCallback } from '../server/routes/helper';
import config from '../config/index.ts';
import { groupByCount, sumByKey } from '../utils/dataAggregation.ts';
import { UsersMeta } from './usersMeta.ts';
import { SavedItem } from './savedItem.ts';
import { failCallback } from '../server/routes/helper.ts';
import { setTimeout } from 'timers/promises';
import { serverLogger } from '@pocket-tools/ts-logger';
import {
Expand All @@ -16,7 +16,7 @@ import {
Highlight,
BatchWriteHighlightsResult,
BatchWriteHighlightsInput,
} from '../__generated__/resolvers-types';
} from '../__generated__/resolvers-types.ts';

export class HighlightsDataService {
public readonly userId: string;
Expand Down
6 changes: 3 additions & 3 deletions servers/annotations-api/src/dataservices/notes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NotesDataService } from './notes';
import { NotesDataService } from './notes.ts';
import { BatchGetCommandOutput } from '@aws-sdk/lib-dynamodb';
import config from '../config';
import { dynamoClient } from '../database/client';
import config from '../config/index.ts';
import { dynamoClient } from '../database/client.ts';

describe('Notes data service', () => {
let dynamoSendStub;
Expand Down
6 changes: 3 additions & 3 deletions servers/annotations-api/src/dataservices/notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import {
QueryCommandInput,
QueryCommandOutput,
} from '@aws-sdk/lib-dynamodb';
import config from '../config';
import { HighlightNote, HighlightNoteEntity } from '../types';
import { backoff } from './utils';
import config from '../config/index.ts';
import { HighlightNote, HighlightNoteEntity } from '../types.ts';
import { backoff } from './utils.ts';
import { NotFoundError } from '@pocket-tools/apollo-utils';

export class NotesDataService {
Expand Down
2 changes: 1 addition & 1 deletion servers/annotations-api/src/dataservices/parserApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { URLSearchParams } from 'url';
import config from '../config';
import config from '../config/index.ts';
import { RESTDataSource } from '@apollo/datasource-rest';
import md5 from 'md5';
import { backOff } from 'exponential-backoff';
Expand Down
6 changes: 3 additions & 3 deletions servers/annotations-api/src/dataservices/savedItem.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Knex } from 'knex';
import { IContext } from '../server/apollo/context';
import { mysqlTimeString } from './utils';
import config from '../config';
import { IContext } from '../server/apollo/context.ts';
import { mysqlTimeString } from './utils.ts';
import config from '../config/index.ts';

export class SavedItem {
private readonly userId: string;
Expand Down
6 changes: 3 additions & 3 deletions servers/annotations-api/src/dataservices/usersMeta.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Knex } from 'knex';
import { mysqlTimeString } from './utils';
import config from '../config';
import { IContext } from '../server/apollo/context';
import { mysqlTimeString } from './utils.ts';
import config from '../config/index.ts';
import { IContext } from '../server/apollo/context.ts';

export class UsersMeta {
public static propertiesMap = {
Expand Down
8 changes: 4 additions & 4 deletions servers/annotations-api/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import config from './config';
import config from './config/index.ts';
import { initSentry } from '@pocket-tools/sentry';

// Init sentry MUST come before any other imports for auto instrumentation to kick in (request isolation)
Expand All @@ -13,7 +13,7 @@ initSentry({
});

import { nodeSDKBuilder } from '@pocket-tools/tracing';
import { unleash } from './unleash';
import { unleash } from './unleash.ts';
nodeSDKBuilder({ ...config.tracing, unleash: unleash() }).then(() => {
startServer(config.app.port).then(async () => {
// init BatchDeleteHandler, SQS queue is not
Expand All @@ -24,6 +24,6 @@ nodeSDKBuilder({ ...config.tracing, unleash: unleash() }).then(() => {
});
});
import { serverLogger } from '@pocket-tools/ts-logger';
import { startServer } from './server';
import { BatchDeleteHandler } from './server/aws/batchDeleteHandler';
import { startServer } from './server/index.ts';
import { BatchDeleteHandler } from './server/aws/batchDeleteHandler.ts';
import { EventEmitter } from 'events';
8 changes: 4 additions & 4 deletions servers/annotations-api/src/models/HighlightsModel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ForbiddenError } from '@pocket-tools/apollo-utils';
import { HighlightsDataService } from '../dataservices/highlights';
import { NotesDataService } from '../dataservices/notes';
import { HighlightsDataService } from '../dataservices/highlights.ts';
import { NotesDataService } from '../dataservices/notes.ts';
import {
BatchWriteHighlightsInput,
BatchWriteHighlightsResult,
Expand All @@ -10,8 +10,8 @@ import {
UpdateHighlightInput,
SavedItemAnnotations,
CreateHighlightByUrlInput,
} from '../__generated__/resolvers-types';
import { ParserAPI } from '../dataservices/parserApi';
} from '../__generated__/resolvers-types.ts';
import { ParserAPI } from '../dataservices/parserApi.ts';

export class HighlightsModel {
constructor(
Expand Down
2 changes: 1 addition & 1 deletion servers/annotations-api/src/server/apollo/buildSchema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { printSubgraphSchema } from '@apollo/subgraph';
import path from 'path';
import fs from 'fs';
import { schema } from './schema';
import { schema } from './schema.ts';

// Add in constraint directives, for pushing to apollo graph os
const sdl = printSubgraphSchema(schema);
Expand Down
18 changes: 11 additions & 7 deletions servers/annotations-api/src/server/apollo/context.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { Knex } from 'knex';
import { HighlightNote } from '../../types';
import { HighlightNote } from '../../types.ts';
import DataLoader from 'dataloader';
import {
AuthenticationError,
PocketContext,
PocketContextManager,
} from '@pocket-tools/apollo-utils';
import express from 'express';
import { dynamoClient, readClient, writeClient } from '../../database/client';
import {
dynamoClient,
readClient,
writeClient,
} from '../../database/client.ts';
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import { createNotesLoader } from '../../dataservices/dataloaders';
import { NotesDataService } from '../../dataservices/notes';
import { HighlightsModel } from '../../models/HighlightsModel';
import { ParserAPI } from '../../dataservices/parserApi';
import { HighlightsDataService } from '../../dataservices/highlights';
import { createNotesLoader } from '../../dataservices/dataloaders.ts';
import { NotesDataService } from '../../dataservices/notes.ts';
import { HighlightsModel } from '../../models/HighlightsModel.ts';
import { ParserAPI } from '../../dataservices/parserApi.ts';
import { HighlightsDataService } from '../../dataservices/highlights.ts';

export interface IContext extends PocketContext {
userId: string;
Expand Down
4 changes: 2 additions & 2 deletions servers/annotations-api/src/server/apollo/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './schema';
export * as typeDefs from './typeDefs';
export * from './schema.ts';
export * as typeDefs from './typeDefs.ts';
4 changes: 2 additions & 2 deletions servers/annotations-api/src/server/apollo/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
BatchWriteHighlightsInput,
Resolvers,
CreateHighlightByUrlInput,
} from '../../__generated__/resolvers-types';
import { IContext } from './context';
} from '../../__generated__/resolvers-types.ts';
import { IContext } from './context.ts';

export const resolvers: Resolvers = {
...PocketDefaultScalars,
Expand Down
4 changes: 2 additions & 2 deletions servers/annotations-api/src/server/apollo/schema.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { buildSubgraphSchema } from '@apollo/subgraph';
import { constraintDirectiveTypeDefs } from 'graphql-constraint-directive/apollo4';
import { gql } from 'graphql-tag';
import typeDefs from './typeDefs';
import { resolvers } from './resolvers';
import typeDefs from './typeDefs.ts';
import { resolvers } from './resolvers.ts';

// Add @constraint directive to the schema
export const schema = buildSubgraphSchema({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { EventEmitter } from 'events';
import { BatchDeleteHandler, BatchDeleteMessage } from './batchDeleteHandler';
import { BatchDeleteHandler, BatchDeleteMessage } from './batchDeleteHandler.ts';
import { DeleteMessageCommand, SQSClient } from '@aws-sdk/client-sqs';
import { HighlightsDataService } from '../../dataservices/highlights';
import { HighlightsDataService } from '../../dataservices/highlights.ts';
import * as Sentry from '@sentry/node';
import { SeverityLevel } from '@sentry/types';
import config from '../../config';
import config from '../../config/index.ts';
import { serverLogger } from '@pocket-tools/ts-logger';
import * as otel from '@opentelemetry/api';

Expand Down
10 changes: 5 additions & 5 deletions servers/annotations-api/src/server/aws/batchDeleteHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import {
QueueAttributeName,
} from '@aws-sdk/client-sqs';
import * as Sentry from '@sentry/node';
import config from '../../config';
import config from '../../config/index.ts';
import { nanoid } from 'nanoid';
import { readClient, writeClient } from '../../database/client';
import { HighlightsDataService } from '../../dataservices/highlights';
import { readClient, writeClient } from '../../database/client.ts';
import { HighlightsDataService } from '../../dataservices/highlights.ts';
import { setTimeout } from 'timers/promises';
import { failCallback } from '../routes/helper';
import { failCallback } from '../routes/helper.ts';
import { serverLogger } from '@pocket-tools/ts-logger';
import { SeverityLevel } from '@sentry/types';
import { sqs } from './sqs';
import { sqs } from './sqs.ts';
import * as otel from '@opentelemetry/api';

export type BatchDeleteMessage = {
Expand Down
2 changes: 1 addition & 1 deletion servers/annotations-api/src/server/aws/sqs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SQS } from '@aws-sdk/client-sqs';
import config from '../../config';
import config from '../../config/index.ts';

export const sqs = new SQS({
region: config.aws.region,
Expand Down
10 changes: 5 additions & 5 deletions servers/annotations-api/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import {
defaultPlugins,
sentryPocketMiddleware,
} from '@pocket-tools/apollo-utils';
import { createApollo4QueryValidationPlugin } from 'graphql-constraint-directive/apollo4';
import { createApollo4QueryValidationPlugin } from 'graphql-constraint-directive/apollo4.js';

import { schema } from './apollo';
import config from '../config';
import { getContext, IContext } from './apollo/context';
import queueDeleteRouter from './routes/queueDelete';
import { schema } from './apollo/index.ts';
import config from '../config/index.ts';
import { getContext, IContext } from './apollo/context.ts';
import queueDeleteRouter from './routes/queueDelete.ts';
import { setMorgan, serverLogger } from '@pocket-tools/ts-logger';

export async function startServer(port: number): Promise<{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { readClient, writeClient } from '../../database/client';
import { readClient, writeClient } from '../../database/client.ts';
import { SQS } from '@aws-sdk/client-sqs';
import { enqueueAnnotationIds, SqsMessage } from './queueDelete';
import { HighlightsDataService } from '../../dataservices/highlights';
import config from '../../config';
import { enqueueAnnotationIds, SqsMessage } from './queueDelete.ts';
import { HighlightsDataService } from '../../dataservices/highlights.ts';
import config from '../../config/index.ts';
import * as Sentry from '@sentry/node';
import { Knex } from 'knex';

Expand Down
14 changes: 7 additions & 7 deletions servers/annotations-api/src/server/routes/queueDelete.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Request, Response, Router } from 'express';
import { checkSchema, Schema } from 'express-validator';
import { dynamoClient, readClient, writeClient } from '../../database/client';
import config from '../../config';
import { sqs } from '../aws/sqs';
import { dynamoClient, readClient, writeClient } from '../../database/client.ts';
import config from '../../config/index.ts';
import { sqs } from '../aws/sqs.ts';
import {
SendMessageBatchCommand,
SendMessageBatchRequestEntry,
} from '@aws-sdk/client-sqs';
import { nanoid } from 'nanoid';
import * as Sentry from '@sentry/node';
import { validate } from './validator';
import { HighlightsDataService } from '../../dataservices/highlights';
import { NotesDataService } from '../../dataservices/notes';
import { failCallback, successCallback } from './helper';
import { validate } from './validator.ts';
import { HighlightsDataService } from '../../dataservices/highlights.ts';
import { NotesDataService } from '../../dataservices/notes.ts';
import { failCallback, successCallback } from './helper.ts';
import { serverLogger } from '@pocket-tools/ts-logger';

export type SqsMessage = {
Expand Down
Loading

0 comments on commit f7d2ef7

Please sign in to comment.