Skip to content

Commit

Permalink
#296: make class deserialization work
Browse files Browse the repository at this point in the history
  • Loading branch information
petermasking committed Aug 22, 2024
1 parent f182a34 commit e7d65d7
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/caching/src/application/ClassSourceBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import { Module } from '../module';
import { FileHelper } from '../utils';

export default class ClassSourceBuilder
{
Expand All @@ -12,7 +13,7 @@ export default class ClassSourceBuilder

build(): string
{
const filename = this.#module.filename;
const filename = FileHelper.addSubExtension(this.#module.filename, 'shared');
const classes = this.#module.reflection.exportedClasses;
const classNames = classes.map(clazz => clazz.name);
const sourceCode = classNames.map(className => `${className}.source = "/${filename}";`);
Expand Down
4 changes: 2 additions & 2 deletions packages/jitar/rollup.definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const SERVER_EXTERNALS =

export const REPLACE_VALUES =
{
'RUNTIME_ERROR_LOCATION': '/jitar/client.js',
'RUNTIME_HOOKS_LOCATION': '/jitar/client.js',
'RUNTIME_ERROR_LOCATION': 'jitar',
'RUNTIME_HOOKS_LOCATION': 'jitar',
'JITAR_LIBRARY_NAME': 'jitar',
};
8 changes: 7 additions & 1 deletion packages/jitar/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export
// InvalidVersionNumber,
// MissingParameterValue,
// ModuleNotAccessible,
// ModuleNotLoaded,
ModuleNotLoaded,
// NoWorkerAvailable,
// ProcedureNotAccessible,
// ProcedureNotFound,
Expand All @@ -39,3 +39,9 @@ export
// startClient,
getClient
} from '@jitar/runtime';

export
{
ClassNotFound,
InvalidClass
} from '@jitar/serialization';
2 changes: 1 addition & 1 deletion packages/runtime/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export { AccessLevels, Segment, Procedure, Implementation, Version, NamedParamet
export { HealthCheck } from './health';
export { MiddlewareManager, Middleware, NextHandler } from './middleware';
export { Gateway, LocalGateway, RemoteGateway, Proxy, Repository, LocalRepository, RemoteRepository, Worker, LocalWorker, RemoteWorker, Service, RunnerService } from './services';
export { File, Files, FileManager, FileNotFound, ImportFunction, ClassModuleLoader, SourceManager } from './source';
export { File, Files, FileManager, FileNotFound, ImportFunction, ClassModuleLoader, SourceManager, ModuleNotLoaded } from './source';

export { default as RuntimeBuilder } from './RuntimeBuilder.js';

Expand Down
7 changes: 5 additions & 2 deletions packages/runtime/src/source/SourceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ export default class SourceManager
{
try
{
// If the specifier is an absolute path, we need to convert it to a path
// relative to the cache folder.

const fullSpecifier = specifier.startsWith('/')
? this.#fileManager.getAbsoluteLocation(specifier)
? this.#fileManager.getAbsoluteLocation(`.${specifier}`)
: specifier;

return await this.#import(fullSpecifier);
}
catch (error: unknown)
Expand Down
1 change: 1 addition & 0 deletions packages/runtime/src/source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
export { default as Files } from './definitions/Files';

export { default as FileNotFound } from './errors/FileNotFound';
export { default as ModuleNotLoaded } from './errors/ModuleNotLoaded';

export { default as FileManager } from './interfaces/FileManager';
export { default as ModuleImporter } from './interfaces/ModuleImporter';
Expand Down

0 comments on commit e7d65d7

Please sign in to comment.