Skip to content
Merged
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ These are the steps @Ethan-Arrowood has been following to synchronize the reposi

### Last Synchronized Commit

`e69e4b9c0c1c94576d306965c511e9c99efbf00c`
`f7d75323a11e9f65b6a838e4afe531eb3f59b593`

## Code of Conduct

Expand Down
3 changes: 2 additions & 1 deletion components/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import { extract } from 'tar-fs';
import gunzip from 'gunzip-maybe';
import type { Logger } from './Logger.ts';

interface ApplicationConfig {
// define known config properties
Expand Down Expand Up @@ -123,7 +124,7 @@
if (application.payload) {
// Given a payload, create a Readable from the Buffer or string
tarball = Readable.from(
application.payload instanceof Buffer ? application.payload : Buffer.from(application.payload, 'base64')

Check failure on line 127 in components/Application.ts

View workflow job for this annotation

GitHub Actions / Build Harper (Node.js v22)

No overload matches this call.

Check failure on line 127 in components/Application.ts

View workflow job for this annotation

GitHub Actions / Build Harper (Node.js v20)

No overload matches this call.

Check failure on line 127 in components/Application.ts

View workflow job for this annotation

GitHub Actions / Build Harper (Node.js v24)

No overload matches this call.

Check failure on line 127 in components/Application.ts

View workflow job for this annotation

GitHub Actions / Unit Test (Node.js v22)

No overload matches this call.

Check failure on line 127 in components/Application.ts

View workflow job for this annotation

GitHub Actions / Unit Test (Node.js v24)

No overload matches this call.

Check failure on line 127 in components/Application.ts

View workflow job for this annotation

GitHub Actions / Unit Test (Node.js v20)

No overload matches this call.
);
} else {
// Given a package, there are a a couple options
Expand Down Expand Up @@ -392,7 +393,7 @@
packageIdentifier?: string;
install?: { command?: string; timeout?: number };
dirPath: string;
logger: any;
logger: Logger;
packageManagerPrefix: string; // can be used to configure a package manager prefix, specifically "sfw".

constructor({ name, payload, packageIdentifier, install }: ApplicationOptions) {
Expand All @@ -401,7 +402,7 @@
this.packageIdentifier = packageIdentifier && derivePackageIdentifier(packageIdentifier);
this.install = install;
this.dirPath = join(getConfigValue(CONFIG_PARAMS.COMPONENTSROOT), name);
this.logger = logger.loggerWithTag(name);

Check failure on line 405 in components/Application.ts

View workflow job for this annotation

GitHub Actions / Build Harper (Node.js v22)

Type '{ notify: (...args: any[]) => any; fatal: (...args: any[]) => any; error: (...args: any[]) => any; warn: (...args: any[]) => any; info: (...args: any[]) => any; debug: (...args: any[]) => any; trace: (...args: any[]) => any; }' is missing the following properties from type 'Logger': logLevel, withTag, loggerWithTag

Check failure on line 405 in components/Application.ts

View workflow job for this annotation

GitHub Actions / Build Harper (Node.js v20)

Type '{ notify: (...args: any[]) => any; fatal: (...args: any[]) => any; error: (...args: any[]) => any; warn: (...args: any[]) => any; info: (...args: any[]) => any; debug: (...args: any[]) => any; trace: (...args: any[]) => any; }' is missing the following properties from type 'Logger': logLevel, withTag, loggerWithTag

Check failure on line 405 in components/Application.ts

View workflow job for this annotation

GitHub Actions / Build Harper (Node.js v24)

Type '{ notify: (...args: any[]) => any; fatal: (...args: any[]) => any; error: (...args: any[]) => any; warn: (...args: any[]) => any; info: (...args: any[]) => any; debug: (...args: any[]) => any; trace: (...args: any[]) => any; }' is missing the following properties from type 'Logger': logLevel, withTag, loggerWithTag

Check failure on line 405 in components/Application.ts

View workflow job for this annotation

GitHub Actions / Unit Test (Node.js v22)

Type '{ notify: (...args: any[]) => any; fatal: (...args: any[]) => any; error: (...args: any[]) => any; warn: (...args: any[]) => any; info: (...args: any[]) => any; debug: (...args: any[]) => any; trace: (...args: any[]) => any; }' is missing the following properties from type 'Logger': logLevel, withTag, loggerWithTag

Check failure on line 405 in components/Application.ts

View workflow job for this annotation

GitHub Actions / Unit Test (Node.js v24)

Type '{ notify: (...args: any[]) => any; fatal: (...args: any[]) => any; error: (...args: any[]) => any; warn: (...args: any[]) => any; info: (...args: any[]) => any; debug: (...args: any[]) => any; trace: (...args: any[]) => any; }' is missing the following properties from type 'Logger': logLevel, withTag, loggerWithTag

Check failure on line 405 in components/Application.ts

View workflow job for this annotation

GitHub Actions / Unit Test (Node.js v20)

Type '{ notify: (...args: any[]) => any; fatal: (...args: any[]) => any; error: (...args: any[]) => any; warn: (...args: any[]) => any; info: (...args: any[]) => any; debug: (...args: any[]) => any; trace: (...args: any[]) => any; }' is missing the following properties from type 'Logger': logLevel, withTag, loggerWithTag
this.packageManagerPrefix = getConfigValue(CONFIG_PARAMS.APPLICATIONS_PACKAGEMANAGERPREFIX);
}
}
Expand Down
5 changes: 3 additions & 2 deletions components/EntryHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { FilesOption } from './deriveGlobOptions.js';
import { deriveURLPath } from './deriveURLPath.js';
import { isMatch } from 'micromatch';
import type { Logger } from './Logger.ts';

export interface BaseEntry {
stats?: Stats;
Expand Down Expand Up @@ -71,16 +72,16 @@
export class EntryHandler extends EventEmitter<EntryHandlerEventMap> {
#component: Component;
#watcher?: FSWatcher;
#logger: any;
#logger: Logger;
#pendingFileReads: Set<Promise<void>>;
#isInitialScanComplete: boolean;
ready: Promise<any[]>;

constructor(name: string, directory: string, config: FilesOption | FileAndURLPathConfig, logger?: any) {
constructor(name: string, directory: string, config: FilesOption | FileAndURLPathConfig, logger?: Logger) {
super();

this.#component = new Component(name, directory, castConfig(config));
this.#logger = logger || harperLogger.loggerWithTag(name);

Check failure on line 84 in components/EntryHandler.ts

View workflow job for this annotation

GitHub Actions / Build Harper (Node.js v22)

Type '{ notify: (...args: any[]) => any; fatal: (...args: any[]) => any; error: (...args: any[]) => any; warn: (...args: any[]) => any; info: (...args: any[]) => any; debug: (...args: any[]) => any; trace: (...args: any[]) => any; }' is missing the following properties from type 'Logger': logLevel, withTag, loggerWithTag

Check failure on line 84 in components/EntryHandler.ts

View workflow job for this annotation

GitHub Actions / Build Harper (Node.js v20)

Type '{ notify: (...args: any[]) => any; fatal: (...args: any[]) => any; error: (...args: any[]) => any; warn: (...args: any[]) => any; info: (...args: any[]) => any; debug: (...args: any[]) => any; trace: (...args: any[]) => any; }' is missing the following properties from type 'Logger': logLevel, withTag, loggerWithTag

Check failure on line 84 in components/EntryHandler.ts

View workflow job for this annotation

GitHub Actions / Build Harper (Node.js v24)

Type '{ notify: (...args: any[]) => any; fatal: (...args: any[]) => any; error: (...args: any[]) => any; warn: (...args: any[]) => any; info: (...args: any[]) => any; debug: (...args: any[]) => any; trace: (...args: any[]) => any; }' is missing the following properties from type 'Logger': logLevel, withTag, loggerWithTag

Check failure on line 84 in components/EntryHandler.ts

View workflow job for this annotation

GitHub Actions / Unit Test (Node.js v22)

Type '{ notify: (...args: any[]) => any; fatal: (...args: any[]) => any; error: (...args: any[]) => any; warn: (...args: any[]) => any; info: (...args: any[]) => any; debug: (...args: any[]) => any; trace: (...args: any[]) => any; }' is missing the following properties from type 'Logger': logLevel, withTag, loggerWithTag

Check failure on line 84 in components/EntryHandler.ts

View workflow job for this annotation

GitHub Actions / Unit Test (Node.js v24)

Type '{ notify: (...args: any[]) => any; fatal: (...args: any[]) => any; error: (...args: any[]) => any; warn: (...args: any[]) => any; info: (...args: any[]) => any; debug: (...args: any[]) => any; trace: (...args: any[]) => any; }' is missing the following properties from type 'Logger': logLevel, withTag, loggerWithTag

Check failure on line 84 in components/EntryHandler.ts

View workflow job for this annotation

GitHub Actions / Unit Test (Node.js v20)

Type '{ notify: (...args: any[]) => any; fatal: (...args: any[]) => any; error: (...args: any[]) => any; warn: (...args: any[]) => any; info: (...args: any[]) => any; debug: (...args: any[]) => any; trace: (...args: any[]) => any; }' is missing the following properties from type 'Logger': logLevel, withTag, loggerWithTag
this.#pendingFileReads = new Set();
this.#isInitialScanComplete = false;
this.ready = once(this, 'ready');
Expand Down
14 changes: 14 additions & 0 deletions components/Logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export interface Logger {
logLevel: string;

notify: (...args: any[]) => void;
fatal: (...args: any[]) => void;
error: (...args: any[]) => void;
warn: (...args: any[]) => void;
info: (...args: any[]) => void;
debug: (...args: any[]) => void;
trace: (...args: any[]) => void;

withTag: (tag: string) => Logger;
loggerWithTag: (tag: string) => Logger;
}
5 changes: 3 additions & 2 deletions components/OptionsWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import harperLogger from '../utility/logging/harper_logger.js';
import { DEFAULT_CONFIG } from './DEFAULT_CONFIG.js';
import { cloneDeep } from 'lodash';
import type { Logger } from './Logger.ts';

export interface Config {
[key: string]: ConfigValue;
Expand Down Expand Up @@ -85,14 +86,14 @@
#scopedConfig?: ConfigValue;
#rootConfig?: Config;
#name: string;
#logger: any;
#logger: Logger;
ready: Promise<any[]>;

constructor(name: string, filePath: string, logger?: any) {
constructor(name: string, filePath: string, logger?: Logger) {
super();
this.#name = name;
this.#filePath = filePath;
this.#logger = logger || harperLogger.loggerWithTag(name);

Check failure on line 96 in components/OptionsWatcher.ts

View workflow job for this annotation

GitHub Actions / Build Harper (Node.js v22)

Type '{ notify: (...args: any[]) => any; fatal: (...args: any[]) => any; error: (...args: any[]) => any; warn: (...args: any[]) => any; info: (...args: any[]) => any; debug: (...args: any[]) => any; trace: (...args: any[]) => any; }' is missing the following properties from type 'Logger': logLevel, withTag, loggerWithTag

Check failure on line 96 in components/OptionsWatcher.ts

View workflow job for this annotation

GitHub Actions / Build Harper (Node.js v20)

Type '{ notify: (...args: any[]) => any; fatal: (...args: any[]) => any; error: (...args: any[]) => any; warn: (...args: any[]) => any; info: (...args: any[]) => any; debug: (...args: any[]) => any; trace: (...args: any[]) => any; }' is missing the following properties from type 'Logger': logLevel, withTag, loggerWithTag

Check failure on line 96 in components/OptionsWatcher.ts

View workflow job for this annotation

GitHub Actions / Build Harper (Node.js v24)

Type '{ notify: (...args: any[]) => any; fatal: (...args: any[]) => any; error: (...args: any[]) => any; warn: (...args: any[]) => any; info: (...args: any[]) => any; debug: (...args: any[]) => any; trace: (...args: any[]) => any; }' is missing the following properties from type 'Logger': logLevel, withTag, loggerWithTag

Check failure on line 96 in components/OptionsWatcher.ts

View workflow job for this annotation

GitHub Actions / Unit Test (Node.js v22)

Type '{ notify: (...args: any[]) => any; fatal: (...args: any[]) => any; error: (...args: any[]) => any; warn: (...args: any[]) => any; info: (...args: any[]) => any; debug: (...args: any[]) => any; trace: (...args: any[]) => any; }' is missing the following properties from type 'Logger': logLevel, withTag, loggerWithTag

Check failure on line 96 in components/OptionsWatcher.ts

View workflow job for this annotation

GitHub Actions / Unit Test (Node.js v24)

Type '{ notify: (...args: any[]) => any; fatal: (...args: any[]) => any; error: (...args: any[]) => any; warn: (...args: any[]) => any; info: (...args: any[]) => any; debug: (...args: any[]) => any; trace: (...args: any[]) => any; }' is missing the following properties from type 'Logger': logLevel, withTag, loggerWithTag

Check failure on line 96 in components/OptionsWatcher.ts

View workflow job for this annotation

GitHub Actions / Unit Test (Node.js v20)

Type '{ notify: (...args: any[]) => any; fatal: (...args: any[]) => any; error: (...args: any[]) => any; warn: (...args: any[]) => any; info: (...args: any[]) => any; debug: (...args: any[]) => any; trace: (...args: any[]) => any; }' is missing the following properties from type 'Logger': logLevel, withTag, loggerWithTag
this.ready = once(this, 'ready');
this.#watcher = chokidar
.watch(filePath, { persistent: false })
Expand Down
22 changes: 18 additions & 4 deletions components/Scope.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { EventEmitter, once } from 'node:events';
import { databaseEventsEmitter } from '../resources/databases.ts';
import { type Server } from '../server/Server.ts';
import { EntryHandler, type EntryHandlerEventMap, type onEntryEventHandler } from './EntryHandler.ts';
import type { Logger } from './Logger.ts';
import { OptionsWatcher, OptionsWatcherEventMap } from './OptionsWatcher.ts';
import { loggerWithTag } from '../utility/logging/harper_logger.js';
import type { Resources } from '../resources/Resources.ts';
Expand All @@ -24,27 +26,37 @@ export interface ApplicationContainment {
verifyPath?: string;
}

export type ScopeEventsMap = {
all: [...args: unknown[]];
close: [];
error: [error: unknown];
ready: [];
[record: string]: [...args: unknown[]];
};

/**
* This class is what is passed to the `handleApplication` function of an extension.
*
* It is imperative that the instance is "ready" before its passed to the `handleApplication` function
* It is imperative that the instance is "ready" before it's passed to the `handleApplication` function
* so that the developer can immediately start using `scope.options`, etc.
*
*/
export class Scope extends EventEmitter {
export class Scope extends EventEmitter<ScopeEventsMap> {
#configFilePath: string;
#directory: string;
#name: string;
#entryHandler?: EntryHandler;
#entryHandlers: EntryHandler[];
#logger: any;
#logger: Logger;
#pendingInitialLoads: Set<Promise<void>>;

options: OptionsWatcher;
resources: Resources;
server: Server;
ready: Promise<any[]>;
applicationContainment?: ApplicationContainment;
databaseEvents: typeof databaseEventsEmitter;

constructor(name: string, directory: string, configFilePath: string, resources: Resources, server: Server) {
super();

Expand All @@ -53,6 +65,8 @@ export class Scope extends EventEmitter {
this.#configFilePath = configFilePath;
this.#logger = loggerWithTag(this.#name);

this.databaseEvents = databaseEventsEmitter;

this.resources = resources;
this.server = server;

Expand All @@ -74,7 +88,7 @@ export class Scope extends EventEmitter {
};
}

get logger(): any {
get logger() {
return this.#logger;
}

Expand Down
4 changes: 3 additions & 1 deletion dataLayer/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const harperBridge = require('./harperBridge/harperBridge.js');
const { handleHDBError, hdbErrors, ClientError } = require('../utility/errors/hdbError.js');
const { HDB_ERROR_MSGS, HTTP_STATUS_CODES } = hdbErrors;
const { SchemaEventMsg } = require('../server/threads/itc.js');
const { getDatabases } = require('../resources/databases.ts');
const { getDatabases, dropTableMeta } = require('../resources/databases.ts');
const { transformReq } = require('../utility/common_utils.js');
const { server } = require('../server/Server.ts');
const { cleanupOrphans } = require('../resources/blob.ts');
Expand Down Expand Up @@ -219,6 +219,8 @@ async function dropTable(dropTableObject) {

await harperBridge.dropTable(dropTableObject);

await dropTableMeta({ table: dropTableObject.table, database: dropTableObject.schema });

let response = await server.replication.replicateOperation(dropTableObject);
response.message = `successfully deleted table '${dropTableObject.schema}.${dropTableObject.table}'`;
return response;
Expand Down
26 changes: 18 additions & 8 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
export { Resource } from './resources/Resource.ts';
import type { Logger } from './components/Logger.ts';
import { BlobCreationOptions } from './resources/blob.ts';
import { databases as dbDatabases, tables as dbTables } from './resources/databases.ts';
import { Resource as ResourceImport } from './resources/Resource.ts';
import { server as serverImport } from './server/Server.ts';

export { Resource } from './resources/Resource.ts';
export type {
Query,
Context,
Query,
RequestTargetOrId,
Session,
SourceContext,
SubscriptionRequest,
RequestTargetOrId,
} from './resources/ResourceInterface.ts';
export { ResourceInterface } from './resources/ResourceInterface.ts';
export type { User } from './security/user.ts';
export type { RecordObject } from './resources/RecordEncoder.ts';
export type { IterableEventQueue } from './resources/IterableEventQueue.ts';
export { RequestTarget } from './resources/RequestTarget.ts';
export { server } from './server/Server';
import { server as serverImport } from './server/Server.ts';
export { tables, databases } from './resources/databases.ts';
import { tables as dbTables, databases as dbDatabases } from './resources/databases.ts';
import { BlobCreationOptions } from './resources/blob.ts';
export { Scope } from './components/Scope.ts';
export { tables, databases, type Table } from './resources/databases.ts';
export type { Attribute } from './resources/Table.ts';

declare const logger: Logger;
export { type Logger, logger };

export type { Scope } from './components/Scope.ts';
export type { FilesOption, FilesOptionObject } from './components/deriveGlobOptions.ts';
export type { FileAndURLPathConfig } from './components/Component.ts';
export { OptionsWatcher, type Config, type ConfigValue } from './components/OptionsWatcher.ts';

export {
EntryHandler,
type BaseEntry,
Expand All @@ -36,6 +45,7 @@ export {
} from './components/EntryHandler.ts';
declare global {
const tables: typeof dbTables;
const logger: Logger;
const databases: typeof dbDatabases;
const server: typeof serverImport;
const Resource: typeof ResourceImport;
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ if (!workerThreads.isMainThread) {
const { globals } = require('./server/threads/threadServer.js');

// exported types are needed for parsing as well
exports.Attribute = undefined;
exports.Config = undefined;
exports.ConfigValue = undefined;
exports.Context = undefined;
exports.FileAndURLPathConfig = undefined;
exports.FilesOption = undefined;
exports.FilesOptionObject = undefined;
exports.IterableEventQueue = undefined;
exports.Logger = undefined;
exports.Query = undefined;
exports.RecordObject = undefined;
exports.RequestTarget = undefined;
Expand All @@ -24,6 +26,7 @@ exports.Scope = undefined;
exports.Session = undefined;
exports.SourceContext = undefined;
exports.SubscriptionRequest = undefined;
exports.Table = undefined;
exports.User = undefined;

// these are all overwritten by the globals, but need to be here so that Node's static
Expand Down
16 changes: 11 additions & 5 deletions resources/Table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,17 @@ const { validateAttribute } = lmdbProcessRows;

export type Attribute = {
name: string;
type: string;
type: 'ID' | 'Int' | 'Float' | 'Long' | 'String' | 'Boolean' | 'Date' | 'Bytes' | 'Any' | 'BigInt' | 'Blob' | string;
assignCreatedTime?: boolean;
assignUpdatedTime?: boolean;
nullable?: boolean;
expiresAt?: boolean;
isPrimaryKey?: boolean;
indexed?: unknown;
relationship?: unknown;
computed?: unknown;
properties?: Array<Attribute>;
elements?: Attribute;
};

type MaybePromise<T> = T | Promise<T>;
Expand Down Expand Up @@ -105,7 +111,7 @@ export interface Table {
databasePath: string;
tableName: string;
databaseName: string;
attributes: any[];
attributes: Attribute[];
primaryKey: string;
splitSegments?: boolean;
replicate?: boolean;
Expand Down Expand Up @@ -140,7 +146,7 @@ export function makeTable(options) {
} = options;
let { expirationMS: expirationMs, evictionMS: evictionMs, audit, trackDeletes } = options;
evictionMs ??= 0;
let { attributes } = options;
let { attributes }: { attributes: Attribute[] } = options;
if (!attributes) attributes = [];
const updateRecord = recordUpdater(primaryStore, tableId, auditStore);
let sourceLoad: any; // if a source has a load function (replicator), record it here
Expand Down Expand Up @@ -2873,7 +2879,7 @@ export function makeTable(options) {
}
validate(record: any, patch?: boolean) {
let validationErrors;
const validateValue = (value, attribute, name) => {
const validateValue = (value, attribute: Attribute, name) => {
if (attribute.type && value != null) {
if (patch && value.__op__) value = value.value;
if (attribute.properties) {
Expand Down Expand Up @@ -3043,7 +3049,7 @@ export function makeTable(options) {
getUpdatedTime() {
return this.#version;
}
static async addAttributes(attributesToAdd) {
static async addAttributes(attributesToAdd: Attribute[]) {
const new_attributes = attributes.slice(0);
for (const attribute of attributesToAdd) {
if (!attribute.name) throw new ClientError('Attribute name is required');
Expand Down
Loading
Loading