Skip to content
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
2 changes: 2 additions & 0 deletions .github/workflows/cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ jobs:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm install
- name: Build
run: npm run build --ws --if-present
- name: Run tests
run: npm run test
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Install dependencies
run: npm install
- name: Build
run: npm run build
run: npm run build --ws --if-present
- name: Run tests
run: npm run coverage
- name: Send coverage report to Codecov
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ jobs:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm install
- name: Build
run: npm run build --ws --if-present
- name: Run tests
run: npm run test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jspm_packages/
# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

Expand Down
27 changes: 14 additions & 13 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
import { ESLintConfig, globals } from "@openally/config.eslint";
// Import Third-party Dependencies
import { ESLintConfig, typescriptConfig, globals } from "@openally/config.eslint";
import jsdoc from "eslint-plugin-jsdoc";

export default [
...ESLintConfig,
{
rules: {
"no-invalid-this": "off"
},
languageOptions: {
sourceType: "module",
globals: {
...globals.browser
}
}
},
{
files: ["public/**/*.js"],
plugins: {
Expand All @@ -34,5 +24,16 @@ export default [
"**/coverage/",
"**/fixtures/"
]
}
},
...typescriptConfig({
rules: {
"no-invalid-this": "off"
},
languageOptions: {
sourceType: "module",
globals: {
...globals.browser
}
}
})
];
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"@nodesecure/size-satisfies": "^1.1.0",
"@nodesecure/vis-network": "^1.4.0",
"@openally/config.eslint": "^2.1.0",
"@openally/config.typescript": "^1.0.3",
"@types/node": "^24.0.3",
"c8": "^10.1.2",
"cross-env": "^7.0.3",
Expand All @@ -80,7 +81,9 @@
"rimraf": "^6.0.1",
"server-destroy": "^1.0.1",
"stylelint": "^16.20.0",
"stylelint-config-standard": "^38.0.0"
"stylelint-config-standard": "^38.0.0",
"tsx": "^4.20.3",
"typescript": "^5.8.3"
},
"dependencies": {
"@nodesecure/documentation-ui": "^1.3.0",
Expand Down
17 changes: 13 additions & 4 deletions src/commands/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import * as i18n from "@nodesecure/i18n";
import { buildServer, WebSocketServerInstanciator } from "@nodesecure/server";
import { appCache } from "@nodesecure/cache";

// Import Internal Dependencies
import english from "../../i18n/english.js";
import french from "../../i18n/french.js";

// CONSTANTS
const kRequiredScannerRange = ">=5.1.0";
const kProjectRootDir = path.join(import.meta.dirname, "..", "..");
Expand All @@ -21,6 +25,7 @@ export async function start(
options = {}
) {
const port = Number(options.port);
const httpPort = Number.isNaN(port) ? 0 : port;
const freshStart = Boolean(options.f);
const enableDeveloperMode = Boolean(options.developer);

Expand All @@ -43,15 +48,19 @@ export async function start(
}

const httpServer = buildServer(dataFilePath, {
port: Number.isNaN(port) ? 0 : port,
port: httpPort,
hotReload: enableDeveloperMode,
runFromPayload,
projectRootDir: kProjectRootDir,
componentsDir: kComponentsDir
componentsDir: kComponentsDir,
i18n: {
english,
french
}
});

httpServer.listen(port, async() => {
const link = `http://localhost:${port}`;
httpServer.listen(httpPort, async() => {
const link = `http://localhost:${httpServer.server.address().port}`;
console.log(kleur.magenta().bold(await i18n.getToken("cli.http_server_started")), kleur.cyan().bold(link));

open(link);
Expand Down
6 changes: 6 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "@openally/config.typescript",
"compilerOptions": {
"composite": true
}
}
11 changes: 11 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"files": [],
"references": [
{
"path": "./workspaces/cache"
},
{
"path": "./workspaces/server"
}
]
}
59 changes: 47 additions & 12 deletions workspaces/cache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ await appCache.setRootPayload(payload);

## API

### `updateConfig(config)`
### `updateConfig(config: AppConfig): Promise<void>`

Stores a new configuration object in the cache.

### `getConfig()`
### `getConfig(): Promise<AppConfig>`

Retrieves the current configuration object from the cache.

### `updatePayload(pkg, payload)`
### `updatePayload(packageName: string, payload: Payload): void`

Saves an analysis payload for a given package.

Expand All @@ -60,18 +60,18 @@ Saves an analysis payload for a given package.
> [!NOTE]
> Payloads are stored in the user's home directory under `~/.nsecure/payloads/`

### `getPayload(pkg)`
### `getPayload(packageName: string): Payload`

Loads an analysis payload for a given package.

**Parameters**:
`pkg` (`string`): Package name.

### `availablePayloads()`
### `availablePayloads(): string[]`

Lists all available payloads (package names) in the cache.

### `getPayloadOrNull(pkg)`
### `getPayloadOrNull(packageName: string): Payload | null`

Loads an analysis payload for a given package, or returns `null` if not found.

Expand All @@ -81,19 +81,19 @@ Loads an analysis payload for a given package, or returns `null` if not found.

Returns `null` if not found.

### `updatePayloadsList(payloadsList)`
### `updatePayloadsList(payloadsList: PayloadsList): Promise<void>`

Updates the internal MRU/LRU and available payloads list.

**Parameters**:

- `payloadsList` (`object`): The new payloads list object.

### `payloadsList()`
### `payloadsList(): Promise<PayloadsList>`

Retrieves the current MRU/LRU and available payloads list.

### `initPayloadsList(options = {})`
### `initPayloadsList(options: InitPayloadListOptions = {}): Promise<void>`

Initializes the payloads list, optionally resetting the cache.

Expand All @@ -103,18 +103,18 @@ Initializes the payloads list, optionally resetting the cache.
- `logging` (`boolean`, default: `true`): Enable logging.
- `reset` (`boolean`, default: `false`): If `true`, reset the cache before initializing.

### `removePayload(pkg)`
### `removePayload(packageName: string): void`

Removes a payload for a given package from the cache.

**Parameters**:
- `pkg` (`string`): Package name.

### `removeLastMRU()`
### `removeLastMRU(): Promise<PayloadsList>`

Removes the least recently used payload if the MRU exceeds the maximum allowed.

### `setRootPayload(payload, options)`
### `setRootPayload(payload: Payload, options: SetRootPayloadOptions = {}): Promise<void>`

Sets a new root payload, updates MRU/LRU, and manages cache state.

Expand All @@ -124,3 +124,38 @@ Sets a new root payload, updates MRU/LRU, and manages cache state.
- `options` (`object`):
- `logging` (`boolean`, default: `true`): Enable logging.
- `local` (`boolean`, default: `false`): Mark the payload as local.

## Interfaces

```ts
interface AppConfig {
defaultPackageMenu: string;
ignore: {
flags: Flag[];
warnings: WarningName[];
};
theme?: "light" | "dark";
disableExternalRequests: boolean;
}

interface PayloadsList {
mru: string[];
lru: string[];
current: string;
availables: string[];
lastUsed: Record<string, number>;
root: string | null;
}

interface LoggingOption {
logging?: boolean;
}

interface InitPayloadListOptions extends LoggingOption {
reset?: boolean;
}

interface SetRootPayloadOptions extends LoggingOption {
local?: boolean;
}
```
Loading