arikajs 0.10.2 → 0.10.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Application.d.ts +1 -1
- package/dist/Application.d.ts.map +1 -1
- package/dist/Application.js +15 -1
- package/dist/Application.js.map +1 -1
- package/dist/facades/Schedule.d.ts +8 -0
- package/dist/facades/Schedule.d.ts.map +1 -0
- package/dist/facades/Schedule.js +25 -0
- package/dist/facades/Schedule.js.map +1 -0
- package/dist/helpers.d.ts +17 -1
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.js +44 -2
- package/dist/helpers.js.map +1 -1
- package/dist/http/Handler.d.ts +4 -0
- package/dist/http/Handler.d.ts.map +1 -1
- package/dist/http/Handler.js +348 -1
- package/dist/http/Handler.js.map +1 -1
- package/dist/http/Kernel.d.ts.map +1 -1
- package/dist/http/Kernel.js +15 -13
- package/dist/http/Kernel.js.map +1 -1
- package/dist/http/Middleware/ViewMiddleware.d.ts.map +1 -1
- package/dist/http/Middleware/ViewMiddleware.js +31 -5
- package/dist/http/Middleware/ViewMiddleware.js.map +1 -1
- package/dist/index.d.ts +9 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -3
- package/dist/index.js.map +1 -1
- package/dist/providers/FrameworkServiceProvider.d.ts.map +1 -1
- package/dist/providers/FrameworkServiceProvider.js +2 -0
- package/dist/providers/FrameworkServiceProvider.js.map +1 -1
- package/dist/providers/QueueServiceProvider.d.ts.map +1 -1
- package/dist/providers/QueueServiceProvider.js +2 -7
- package/dist/providers/QueueServiceProvider.js.map +1 -1
- package/dist/providers/StorageServiceProvider.d.ts +12 -0
- package/dist/providers/StorageServiceProvider.d.ts.map +1 -0
- package/dist/providers/StorageServiceProvider.js +41 -0
- package/dist/providers/StorageServiceProvider.js.map +1 -0
- package/dist/providers/ViewServiceProvider.d.ts.map +1 -1
- package/dist/providers/ViewServiceProvider.js +4 -0
- package/dist/providers/ViewServiceProvider.js.map +1 -1
- package/package.json +27 -22
- package/CHANGELOG.md +0 -124
- package/src/Application.ts +0 -236
- package/src/Contracts/Application.ts +0 -24
- package/src/createApp.ts +0 -9
- package/src/helpers.ts +0 -106
- package/src/http/Handler.ts +0 -184
- package/src/http/Kernel.ts +0 -108
- package/src/http/Middleware/RequestLoggingMiddleware.ts +0 -17
- package/src/http/Middleware/ServeStaticMiddleware.ts +0 -34
- package/src/http/Middleware/ValidateRequestMiddleware.ts +0 -35
- package/src/http/Middleware/VerifyCsrfToken.ts +0 -101
- package/src/http/Middleware/ViewMiddleware.ts +0 -24
- package/src/http/views/errors/401.ark.html +0 -57
- package/src/http/views/errors/403.ark.html +0 -54
- package/src/http/views/errors/404.ark.html +0 -179
- package/src/http/views/errors/419.ark.html +0 -54
- package/src/http/views/errors/429.ark.html +0 -54
- package/src/http/views/errors/500.ark.html +0 -54
- package/src/http/views/errors/503.ark.html +0 -49
- package/src/index.ts +0 -75
- package/src/providers/AuthServiceProvider.ts +0 -28
- package/src/providers/CacheServiceProvider.ts +0 -29
- package/src/providers/DatabaseServiceProvider.ts +0 -46
- package/src/providers/EventsServiceProvider.ts +0 -19
- package/src/providers/FrameworkServiceProvider.ts +0 -44
- package/src/providers/HttpServiceProvider.ts +0 -37
- package/src/providers/LoggingServiceProvider.ts +0 -17
- package/src/providers/MailServiceProvider.ts +0 -33
- package/src/providers/QueueServiceProvider.ts +0 -36
- package/src/providers/SchedulerServiceProvider.ts +0 -18
- package/src/providers/SessionServiceProvider.ts +0 -68
- package/src/providers/TranslationServiceProvider.ts +0 -51
- package/src/providers/ValidationServiceProvider.ts +0 -24
- package/src/providers/ViewServiceProvider.ts +0 -46
- package/tests/Framework.test.ts +0 -140
- package/tsconfig.json +0 -25
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { ServiceProvider } from '@arikajs/foundation';
|
|
3
|
-
import { SessionManager } from '@arikajs/session';
|
|
4
|
-
import { StartSession } from '@arikajs/session';
|
|
5
|
-
import * as path from 'path';
|
|
6
|
-
|
|
7
|
-
export class SessionServiceProvider extends ServiceProvider {
|
|
8
|
-
/**
|
|
9
|
-
* Register the session manager as a singleton.
|
|
10
|
-
*/
|
|
11
|
-
public async register(): Promise<void> {
|
|
12
|
-
this.app.singleton(SessionManager, () => {
|
|
13
|
-
const config = this.app.config();
|
|
14
|
-
const basePath = (this.app as any).getBasePath();
|
|
15
|
-
|
|
16
|
-
const sessionConfig: any = {
|
|
17
|
-
driver: config.get('session.driver', 'file'),
|
|
18
|
-
lifetime: config.get('session.lifetime', 120), // minutes
|
|
19
|
-
cookie: config.get('session.cookie', 'arika_session'),
|
|
20
|
-
path: config.get('session.path', '/'),
|
|
21
|
-
storagePath: config.get('session.storagePath',
|
|
22
|
-
path.join(basePath, 'storage', 'sessions')),
|
|
23
|
-
secure: config.get('session.secure', false),
|
|
24
|
-
httpOnly: config.get('session.httpOnly', true),
|
|
25
|
-
sameSite: config.get('session.sameSite', 'Lax'),
|
|
26
|
-
locking: config.get('session.locking', false),
|
|
27
|
-
lockTimeout: config.get('session.lockTimeout', 10),
|
|
28
|
-
gcProbability: config.get('session.gcProbability', 0.01),
|
|
29
|
-
secret: config.get('app.key', 'fallback-secret-change-me'),
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
if (sessionConfig.driver === 'database') {
|
|
33
|
-
try {
|
|
34
|
-
// Try to resolve the database manager from the container
|
|
35
|
-
const dbManager = this.app.make('db');
|
|
36
|
-
sessionConfig.connection = dbManager; // passing manager or connection directly
|
|
37
|
-
sessionConfig.table = config.get('session.table', 'sessions');
|
|
38
|
-
} catch {
|
|
39
|
-
// Framework fallback
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (sessionConfig.driver === 'redis') {
|
|
44
|
-
try {
|
|
45
|
-
// Try to resolve redis from container or cache store
|
|
46
|
-
const redis = this.app.make('redis') || (this.app.make('cache') as any).store('redis').getRedis();
|
|
47
|
-
sessionConfig.connection = redis;
|
|
48
|
-
sessionConfig.prefix = config.get('session.prefix', 'arika_session:');
|
|
49
|
-
} catch {
|
|
50
|
-
// Framework fallback
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return new SessionManager(sessionConfig);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
this.app.singleton('session', () => this.app.make(SessionManager));
|
|
58
|
-
|
|
59
|
-
this.app.singleton(StartSession, () => {
|
|
60
|
-
return new StartSession(this.app.make(SessionManager));
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Boot — nothing required.
|
|
66
|
-
*/
|
|
67
|
-
public async boot(): Promise<void> { }
|
|
68
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { ServiceProvider } from '@arikajs/foundation';
|
|
2
|
-
import { Translator } from '@arikajs/localization';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import fs from 'fs';
|
|
5
|
-
|
|
6
|
-
export class TranslationServiceProvider extends ServiceProvider {
|
|
7
|
-
/**
|
|
8
|
-
* Register the translation service.
|
|
9
|
-
*/
|
|
10
|
-
public register(): void {
|
|
11
|
-
this.app.singleton(Translator, () => {
|
|
12
|
-
const config = (this.app as any).config();
|
|
13
|
-
const locale = config.get('app.locale', 'en');
|
|
14
|
-
const fallbackLocale = config.get('app.fallback_locale', 'en');
|
|
15
|
-
|
|
16
|
-
const translator = new Translator(locale, fallbackLocale);
|
|
17
|
-
|
|
18
|
-
// Load translations from resources/lang
|
|
19
|
-
this.loadTranslations(translator);
|
|
20
|
-
|
|
21
|
-
return translator;
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Load translations from the application's language directory.
|
|
27
|
-
*/
|
|
28
|
-
private loadTranslations(translator: Translator): void {
|
|
29
|
-
const langPath = path.join(process.cwd(), 'resources', 'lang');
|
|
30
|
-
|
|
31
|
-
if (!fs.existsSync(langPath)) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const locales = fs.readdirSync(langPath);
|
|
36
|
-
|
|
37
|
-
for (const locale of locales) {
|
|
38
|
-
const localePath = path.join(langPath, locale);
|
|
39
|
-
if (!fs.statSync(localePath).isDirectory()) continue;
|
|
40
|
-
|
|
41
|
-
const files = fs.readdirSync(localePath);
|
|
42
|
-
for (const file of files) {
|
|
43
|
-
if (file.endsWith('.json')) {
|
|
44
|
-
const group = path.basename(file, '.json');
|
|
45
|
-
const content = JSON.parse(fs.readFileSync(path.join(localePath, file), 'utf-8'));
|
|
46
|
-
translator.load(locale, group, content);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { ServiceProvider } from '@arikajs/foundation';
|
|
3
|
-
import { Validator } from '@arikajs/validation';
|
|
4
|
-
import { ValidateRequestMiddleware } from '../http/Middleware/ValidateRequestMiddleware';
|
|
5
|
-
|
|
6
|
-
export class ValidationServiceProvider extends ServiceProvider {
|
|
7
|
-
/**
|
|
8
|
-
* Register validation services.
|
|
9
|
-
*/
|
|
10
|
-
public async register() {
|
|
11
|
-
this.app.singleton('validator', () => {
|
|
12
|
-
return {
|
|
13
|
-
make: (data: any, rules: any, messages: any = {}) => {
|
|
14
|
-
return new Validator(data, rules, messages);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
// Register the validation middleware
|
|
20
|
-
this.app.bind(ValidateRequestMiddleware, () => {
|
|
21
|
-
return new ValidateRequestMiddleware();
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { ServiceProvider } from '@arikajs/foundation';
|
|
3
|
-
import { View } from '@arikajs/view';
|
|
4
|
-
import path from 'path';
|
|
5
|
-
import { ViewMiddleware } from '../http/Middleware/ViewMiddleware';
|
|
6
|
-
|
|
7
|
-
export class ViewServiceProvider extends ServiceProvider {
|
|
8
|
-
/**
|
|
9
|
-
* Register the service provider.
|
|
10
|
-
*/
|
|
11
|
-
public async register(): Promise<void> {
|
|
12
|
-
this.app.singleton(View, () => {
|
|
13
|
-
const config = this.app.config();
|
|
14
|
-
const viewsPath = config.get('view.paths', [
|
|
15
|
-
path.join((this.app as any).getBasePath(), 'resources/views')
|
|
16
|
-
])[0] as string;
|
|
17
|
-
|
|
18
|
-
const cachePath = config.get('view.cache_path',
|
|
19
|
-
path.join((this.app as any).getBasePath(), 'storage/framework/views')
|
|
20
|
-
) as string;
|
|
21
|
-
|
|
22
|
-
const view = new View({
|
|
23
|
-
viewsPath,
|
|
24
|
-
cachePath,
|
|
25
|
-
cache: config.get('app.env') === 'production'
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
view.helper('config', (key: string, defaultValue?: any) => config.get(key, defaultValue));
|
|
29
|
-
|
|
30
|
-
return view;
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
this.app.singleton('view', () => this.app.make(View));
|
|
34
|
-
|
|
35
|
-
this.app.singleton(ViewMiddleware, () => {
|
|
36
|
-
return new ViewMiddleware(this.app.make(View));
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Boot the service provider.
|
|
42
|
-
*/
|
|
43
|
-
public async boot(): Promise<void> {
|
|
44
|
-
//
|
|
45
|
-
}
|
|
46
|
-
}
|
package/tests/Framework.test.ts
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import test, { describe, it } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
import { createApp } from '../src';
|
|
4
|
-
import { Router } from '@arikajs/router';
|
|
5
|
-
import { ServerResponse } from 'node:http';
|
|
6
|
-
|
|
7
|
-
describe('ArikaJS Framework', () => {
|
|
8
|
-
it('can create an application instance', () => {
|
|
9
|
-
const app = createApp();
|
|
10
|
-
assert.ok(app instanceof Object);
|
|
11
|
-
assert.ok(app.getRouter() instanceof Router);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('can register routes through the app', () => {
|
|
15
|
-
const app = createApp();
|
|
16
|
-
app.get('/test', () => 'hello');
|
|
17
|
-
|
|
18
|
-
const matched = app.getRouter().match('GET', '/test');
|
|
19
|
-
assert.ok(matched !== null);
|
|
20
|
-
assert.strictEqual(matched.route.path, '/test');
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('boots correctly', async () => {
|
|
24
|
-
const app = createApp();
|
|
25
|
-
app.config().set('app.key', 'base64:sm957Y1wUYo8Uj8yL1fD7vX+X6y8gG+E6XpXnJz+I=');
|
|
26
|
-
await app.boot();
|
|
27
|
-
assert.ok(app.isBooted());
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('can handle requests through the kernel', async () => {
|
|
31
|
-
const app = createApp();
|
|
32
|
-
app.config().set('app.key', 'base64:sm957Y1wUYo8Uj8yL1fD7vX+X6y8gG+E6XpXnJz+I=');
|
|
33
|
-
app.config().set('logging', {
|
|
34
|
-
default: 'console',
|
|
35
|
-
channels: {
|
|
36
|
-
console: {
|
|
37
|
-
driver: 'console'
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
app.get('/hello', () => ({ message: 'world' }));
|
|
43
|
-
|
|
44
|
-
await app.boot();
|
|
45
|
-
|
|
46
|
-
const { Kernel } = await import('../src/http/Kernel');
|
|
47
|
-
const { Request, Response } = await import('@arikajs/http');
|
|
48
|
-
|
|
49
|
-
const kernel = new Kernel(app);
|
|
50
|
-
|
|
51
|
-
// Mock Node.js response
|
|
52
|
-
const mockRes = {
|
|
53
|
-
setHeader: () => { },
|
|
54
|
-
writeHead: () => { },
|
|
55
|
-
end: () => { },
|
|
56
|
-
statusCode: 200
|
|
57
|
-
} as unknown as ServerResponse;
|
|
58
|
-
|
|
59
|
-
const request = new Request(app, { method: 'GET', url: '/hello', headers: {} } as any);
|
|
60
|
-
const response = new Response(mockRes);
|
|
61
|
-
|
|
62
|
-
const result = await kernel.handle(request, response);
|
|
63
|
-
|
|
64
|
-
assert.strictEqual(result.getContent(), JSON.stringify({ message: 'world' }));
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('handles CORS preflight requests', async () => {
|
|
68
|
-
const app = createApp();
|
|
69
|
-
app.config().set('app.key', 'base64:sm957Y1wUYo8Uj8yL1fD7vX+X6y8gG+E6XpXnJz+I=');
|
|
70
|
-
await app.boot();
|
|
71
|
-
|
|
72
|
-
const { Kernel } = await import('../src/http/Kernel');
|
|
73
|
-
const { Request, Response } = await import('@arikajs/http');
|
|
74
|
-
const { ServerResponse } = await import('node:http');
|
|
75
|
-
|
|
76
|
-
const kernel = new Kernel(app);
|
|
77
|
-
|
|
78
|
-
const mockRes = {
|
|
79
|
-
setHeader: (name: string, value: string) => {
|
|
80
|
-
mockRes.headers[name] = value;
|
|
81
|
-
},
|
|
82
|
-
writeHead: () => { },
|
|
83
|
-
end: () => { },
|
|
84
|
-
statusCode: 200,
|
|
85
|
-
headers: {} as Record<string, string>
|
|
86
|
-
} as unknown as ServerResponse & { headers: Record<string, string> };
|
|
87
|
-
|
|
88
|
-
const request = new Request(app, { method: 'OPTIONS', url: '/any', headers: {} } as any);
|
|
89
|
-
const response = new Response(mockRes);
|
|
90
|
-
|
|
91
|
-
const result = await kernel.handle(request, response);
|
|
92
|
-
kernel.terminate(request, result);
|
|
93
|
-
|
|
94
|
-
assert.strictEqual(mockRes.statusCode, 204);
|
|
95
|
-
assert.strictEqual(mockRes.headers['Access-Control-Allow-Origin'], '*');
|
|
96
|
-
assert.strictEqual(mockRes.headers['Access-Control-Allow-Methods'], 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('initializes the database manager and facade', async () => {
|
|
100
|
-
const app = createApp();
|
|
101
|
-
app.config().set('app.key', 'base64:sm957Y1wUYo8Uj8yL1fD7vX+X6y8gG+E6XpXnJz+I=');
|
|
102
|
-
app.config().set('database', {
|
|
103
|
-
default: 'sqlite',
|
|
104
|
-
connections: {
|
|
105
|
-
sqlite: {
|
|
106
|
-
driver: 'sqlite',
|
|
107
|
-
database: ':memory:'
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
await app.boot();
|
|
113
|
-
|
|
114
|
-
const { DatabaseManager, Database } = await import('@arikajs/database');
|
|
115
|
-
|
|
116
|
-
const manager = app.make(DatabaseManager);
|
|
117
|
-
assert.ok(manager instanceof DatabaseManager);
|
|
118
|
-
assert.strictEqual(manager, Database.getManager());
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it('provides global helpers', async () => {
|
|
122
|
-
const appInstance = createApp();
|
|
123
|
-
appInstance.config().set('app.name', 'ArikaTest');
|
|
124
|
-
|
|
125
|
-
const { app: appHelper, config: configHelper } = await import('../src');
|
|
126
|
-
|
|
127
|
-
assert.strictEqual(appHelper(), appInstance);
|
|
128
|
-
assert.strictEqual(configHelper('app.name'), 'ArikaTest');
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('initializes the event facade', async () => {
|
|
132
|
-
const appInstance = createApp();
|
|
133
|
-
appInstance.config().set('app.key', 'base64:sm957Y1wUYo8Uj8yL1fD7vX+X6y8gG+E6XpXnJz+I=');
|
|
134
|
-
|
|
135
|
-
await appInstance.boot();
|
|
136
|
-
|
|
137
|
-
const { Event } = await import('@arikajs/events');
|
|
138
|
-
assert.ok(Event.getManager() !== null);
|
|
139
|
-
});
|
|
140
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"module": "CommonJS",
|
|
5
|
-
"moduleResolution": "Node",
|
|
6
|
-
"strict": true,
|
|
7
|
-
"esModuleInterop": true,
|
|
8
|
-
"forceConsistentCasingInFileNames": true,
|
|
9
|
-
"skipLibCheck": true,
|
|
10
|
-
"declaration": true,
|
|
11
|
-
"declarationMap": true,
|
|
12
|
-
"sourceMap": true,
|
|
13
|
-
"outDir": "dist",
|
|
14
|
-
"rootDir": "src",
|
|
15
|
-
"experimentalDecorators": true,
|
|
16
|
-
"emitDecoratorMetadata": true
|
|
17
|
-
},
|
|
18
|
-
"include": [
|
|
19
|
-
"src/**/*"
|
|
20
|
-
],
|
|
21
|
-
"exclude": [
|
|
22
|
-
"node_modules",
|
|
23
|
-
"dist"
|
|
24
|
-
]
|
|
25
|
-
}
|