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

setup for typescript, eslint, prettier git hooks & nx configuration #1139

Closed
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { objectIdToCurrent, collectionPermissionsWithAnonRead } = require('../../
const ControlledCollectionMixin = require('../../../mixins/controlled-collection');
const { ACTOR_TYPES } = require('../../../constants');

/** @type {import('moleculer').ServiceSchema} */
const InboxService = {
name: 'activitypub.inbox',
mixins: [ControlledCollectionMixin],
Expand Down
21 changes: 12 additions & 9 deletions src/middleware/packages/backup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,31 @@ const { CronJob } = require('cron');
const fsCopy = require('./utils/fsCopy');
const ftpCopy = require('./utils/ftpCopy');
const rsyncCopy = require('./utils/rsyncCopy');
/**
* @typedef {import('moleculer').Context} Context
Laurin-W marked this conversation as resolved.
Show resolved Hide resolved
*/

/** @type {import('./indexTypes').BackupService} */
const BackupService = {
name: 'backup',
settings: {
localServer: {
fusekiBackupsPath: null,
otherDirsPaths: {}
otherDirsPaths: {},
},
copyMethod: 'rsync', // rsync, ftp or fs
copyMethod: 'rsync', // rsync, ftp, or fs
remoteServer: {
path: null, // Required
user: null, // Required by rsync and ftp
password: null, // Required by rsync and ftp
host: null, // Required by rsync and ftp
port: null // Required by ftp
port: null, // Required by ftp
},
// Required for automated backups
cronJob: {
time: null,
timeZone: 'Europe/Paris'
}
timeZone: 'Europe/Paris',
},
},
dependencies: ['triplestore'],
started() {
Expand All @@ -46,7 +49,7 @@ const BackupService = {
return;
}

// Generate new backup of all datasets
// Generate a new backup of all datasets
const datasets = await ctx.call('triplestore.dataset.list');
for (const dataset of datasets) {
this.logger.info(`Backing up dataset: ${dataset}`);
Expand Down Expand Up @@ -92,10 +95,10 @@ const BackupService = {
break;

default:
throw new Error(`Unknow copy method: ${copyMethod}`);
throw new Error(`Unknown copy method: ${copyMethod}`);
}
}
}
},
},
};

module.exports = BackupService;
41 changes: 41 additions & 0 deletions src/middleware/packages/backup/indexTypes.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Context, ServiceSchema, CallingOptions } from 'moleculer';
import { CronJob } from 'cron';
Laurin-W marked this conversation as resolved.
Show resolved Hide resolved

interface LocalServerSettings {
fusekiBackupsPath: string | null;
otherDirsPaths: Record<string, string>;
}

interface RemoteServerSettings {
path: string | null;
user?: string | null;
password?: string | null;
host?: string | null;
port?: number | null;
}

interface CronJobSettings {
time: string | null;
timeZone?: string;
}

interface BackupServiceSettings {
localServer: LocalServerSettings;
copyMethod: 'rsync' | 'ftp' | 'fs';
remoteServer: RemoteServerSettings;
cronJob: CronJobSettings;
}

interface BackupServiceActions {
backupAll: (ctx: Context, opts?: CallingOptions | undefined) => Promise<void>;
backupDatasets: (ctx: Context, opts?: CallingOptions | undefined) => Promise<void>;
backupOtherDirs: (ctx: Context, opts?: CallingOptions | undefined) => Promise<void>;
copyToRemoteServer: (ctx: Context, opts?: CallingOptions | undefined) => Promise<void>;
}

export interface BackupService extends ServiceSchema {
name: 'backup';
settings: BackupServiceSettings;
dependencies: ['triplestore'];
actions: BackupServiceActions & ServiceSchema['actions'];
}
3 changes: 3 additions & 0 deletions src/middleware/packages/backup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
},
"engines": {
"node": ">=14"
},
"devDependencies": {
"@types/cron": "^2.0.1"
}
}
28 changes: 28 additions & 0 deletions src/middleware/packages/core/service.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Context, ServiceSettingSchema } from 'moleculer';

export interface CoreServiceSettings extends ServiceSettingSchema {
baseUrl: string;
baseDir: string;
triplestore: {
url: string;
user: string;
password: string;
mainDataset: string;
};
// Optional
containers?: string;
jsonContext?: string;
ontologies?: string;
// Services configurations, TODO
activitypub: object;
api: object;
jsonld: object;
ldp: object;
signature: object;
sparqlEndpoint: object;
void: object;
webacl: object;
webfinger: object;
}

export interface MethodAuthenticateContext extends Context {}
26 changes: 17 additions & 9 deletions src/middleware/packages/core/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,28 @@ const { WebAclService } = require('@semapps/webacl');
const { WebfingerService } = require('@semapps/webfinger');
const defaultOntologies = require('./config/ontologies.json');

/**
* @typedef {import('http').ServerResponse} ServerResponse
* @typedef {import('http').IncomingMessage} IncomingMessage
* @typedef {import('./serviceTypes').CoreServiceSettings} CoreServiceSettings
*/

/** @type {import('moleculer').ServiceSchema<CoreServiceSettings>} */
const CoreService = {
name: 'core',
settings: {
baseUrl: null,
baseDir: null,
baseUrl: undefined,
baseDir: undefined,
triplestore: {
url: null,
user: null,
password: null,
mainDataset: null
url: undefined,
user: undefined,
password: undefined,
mainDataset: undefined
},
// Optional
containers: null,
jsonContext: null,
ontologies: null,
containers: undefined,
jsonContext: undefined,
ontologies: undefined,
// Services configurations
activitypub: {},
api: {},
Expand All @@ -47,6 +54,7 @@ const CoreService = {

if (this.settings.activitypub !== false) {
this.broker.createService(ActivityPubService, {
// Type support for settings could be given, once moleculer type definitions improve...
settings: {
baseUri: baseUrl,
jsonContext: jsonContext || defaultJsonContext,
Expand Down
28 changes: 28 additions & 0 deletions src/middleware/packages/core/serviceTypes.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Context, ServiceSettingSchema } from 'moleculer';

export interface CoreServiceSettings extends ServiceSettingSchema {
baseUrl?: string;
baseDir?: string;
triplestore: {
url?: string;
user?: string;
password?: string;
mainDataset?: string;
};
// Optional
containers?: string;
jsonContext?: string;
ontologies?: string;
// Services configurations, no typings yet.
activitypub: object;
api: object;
jsonld: object;
ldp: object;
signature: object;
sparqlEndpoint: object;
void: object;
webacl: object;
webfinger: object;
}

export interface MethodAuthenticateContext extends Context {}
1 change: 1 addition & 0 deletions src/middleware/packages/webacl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"url": "https://github.com/assemblee-virtuelle/semapps/issues"
},
"dependencies": {
"@semapps/ldp": "0.5.1",
"@semapps/middlewares": "0.5.1",
"@semapps/mime-types": "0.5.1",
"@semapps/triplestore": "0.5.1",
Expand Down
4 changes: 4 additions & 0 deletions src/middleware/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
{
"compilerOptions": {
"lib": ["es2020"],
"allowJs": true,
"checkJs": true,
"resolveJsonModule": true,
"declaration": true,
"noEmit": true,
"noLib": false,
"skipLibCheck": true,
"sourceMap": true,
"strictNullChecks": true
},
"include": ["**/*.js", "**/*.ts"],
"exclude": ["node_modules"]
}
13 changes: 13 additions & 0 deletions src/middleware/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1775,6 +1775,14 @@
dependencies:
"@types/node" "*"

"@types/cron@^2.0.1":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@types/cron/-/cron-2.0.1.tgz#d8bf7a24475f64197c7ac868c362b41be596e5f8"
integrity sha512-WHa/1rtNtD2Q/H0+YTTZoty+/5rcE66iAFX2IY+JuUoOACsevYyFkSYu/2vdw+G5LrmO7Lxowrqm0av4k3qWNQ==
dependencies:
"@types/luxon" "*"
"@types/node" "*"

"@types/express-serve-static-core@^4.17.18":
version "4.17.27"
resolved "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.27.tgz"
Expand Down Expand Up @@ -1866,6 +1874,11 @@
dependencies:
"@types/node" "*"

"@types/luxon@*":
version "3.3.0"
resolved "https://registry.yarnpkg.com/@types/luxon/-/luxon-3.3.0.tgz#a61043a62c0a72696c73a0a305c544c96501e006"
integrity sha512-uKRI5QORDnrGFYgcdAVnHvEIvEZ8noTpP/Bg+HeUzZghwinDlIS87DEenV5r1YoOF9G4x600YsUXLWZ19rmTmg==

"@types/mime@^1":
version "1.3.2"
resolved "https://registry.npmjs.org/@types/mime/-/mime-1.3.2.tgz"
Expand Down
Loading