Skip to content

Commit

Permalink
refactor(core): make imports esm-compatible (#1956)
Browse files Browse the repository at this point in the history
  • Loading branch information
AviVahl authored Aug 8, 2023
1 parent d33e966 commit aed4aaf
Show file tree
Hide file tree
Showing 51 changed files with 250 additions and 250 deletions.
56 changes: 27 additions & 29 deletions packages/core/src/com/communication.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,51 @@
import { SetMultiMap } from '@wixc3/patterns';
import { deferred } from 'promise-assist';
import type { ContextualEnvironment, Environment, EnvironmentMode } from '../entities/env.js';
import { serializeError } from '../helpers/index.js';
import { SERVICE_CONFIG } from '../symbols.js';
import { isDisposable, type IDTag } from '../types.js';
import {
CALLBACK_TIMEOUT,
DUPLICATE_REGISTER,
ENV_DISCONNECTED,
REMOTE_CALL_FAILED,
reportError,
UNKNOWN_CALLBACK_ID,
} from './errors';
} from './errors.js';
import {
deserializeApiCallArguments,
isWindow,
isWorkerContext,
MultiCounter,
serializeApiCallArguments,
deserializeApiCallArguments,
} from './helpers';
} from './helpers.js';
import { BaseHost } from './hosts/base-host.js';
import { WsClientHost } from './hosts/ws-client-host.js';
import type {
CallbackMessage,
CallMessage,
EventMessage,
ListenMessage,
UnListenMessage,
Message,
ReadyMessage,
} from './message-types';
UnListenMessage,
} from './message-types.js';
import { isMessage } from './message-types.js';
import {
APIService,
AsyncApi,
CallbackRecord,
EnvironmentInstanceToken,
EnvironmentRecord,
RemoteAPIServicesMapping,
SerializableArguments,
SerializableMethod,
Target,
UnknownFunction,
AnyServiceMethodOptions,
ServiceComConfig,
HOST_REMOVED,
} from './types';

import { SERVICE_CONFIG } from '../symbols';

import { serializeError } from '../helpers';
import { SetMultiMap } from '@wixc3/patterns';
import type { Environment, ContextualEnvironment, EnvironmentMode } from '../entities/env';
import { type IDTag, isDisposable } from '../types';
import { BaseHost } from './hosts/base-host';
import { WsClientHost } from './hosts/ws-client-host';
import { isMessage } from './message-types';
import { deferred } from 'promise-assist';
type AnyServiceMethodOptions,
type APIService,
type AsyncApi,
type CallbackRecord,
type EnvironmentInstanceToken,
type EnvironmentRecord,
type RemoteAPIServicesMapping,
type SerializableArguments,
type SerializableMethod,
type ServiceComConfig,
type Target,
type UnknownFunction,
} from './types.js';

export interface ConfigEnvironmentRecord extends EnvironmentRecord {
registerMessageHandler?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/com/errors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Message } from './message-types';
import type { Message } from './message-types.js';

export const DUPLICATE_REGISTER = (id: string, type: 'RemoteService' | 'Environment') =>
`Could not register same id ${id} as ${type}`;
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/com/hosts/base-host.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Message } from '../message-types';
import type { Target } from '../types';
import type { Message } from '../message-types.js';
import type { Target } from '../types.js';

export class BaseHost implements Target {
constructor(public name = 'base-host') {}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/com/hosts/event-emitter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { EventEmitter } from '@wixc3/patterns';
import type { Message } from '../message-types';
import { BaseHost } from './base-host';
import type { Message } from '../message-types.js';
import { BaseHost } from './base-host.js';

export class EventEmitterHost extends BaseHost {
constructor(private host: EventEmitter<{ message: Message }>) {
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/com/hosts/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './base-host';
export * from './event-emitter';
export * from './universal-worker-host';
export * from './ws-client-host';
export * from './base-host.js';
export * from './event-emitter.js';
export * from './universal-worker-host.js';
export * from './ws-client-host.js';
3 changes: 1 addition & 2 deletions packages/core/src/com/hosts/universal-worker-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import type {
UniversalWorker,
UniversalWorkerUserMethods,
} from '@wixc3/isomorphic-worker/types';

import { Target } from '../types';
import { type Target } from '../types.js';

export class UniversalWorkerHost implements Target {
private messageHandlersMap = new Map<(event: { data: any }) => void, UniversalMessageHandler>();
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/com/hosts/ws-client-host.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { io, Socket, SocketOptions } from 'socket.io-client';
import type { Message } from '../message-types';
import { BaseHost } from './base-host';
import { io, Socket, type SocketOptions } from 'socket.io-client';
import type { Message } from '../message-types.js';
import { BaseHost } from './base-host.js';
import { EventEmitter } from '@wixc3/patterns';
import { deferred } from 'promise-assist';

Expand Down
24 changes: 12 additions & 12 deletions packages/core/src/com/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export * from './hosts/base-host';
export * from './communication';
export * from './errors';
export * from './helpers';
export * from './logger-service';
export * from './window-initializer-service';
export * from './message-types';
export * from './service-config';
export * from './types';
export * from './hosts/ws-client-host';
export * from './initializers';
export * from './hosts';
export * from './hosts/base-host.js';
export * from './communication.js';
export * from './errors.js';
export * from './helpers.js';
export * from './logger-service.js';
export * from './window-initializer-service.js';
export * from './message-types.js';
export * from './service-config.js';
export * from './types.js';
export * from './hosts/ws-client-host.js';
export * from './initializers/index.js';
export * from './hosts/index.js';
6 changes: 3 additions & 3 deletions packages/core/src/com/initializers/contextual.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ContextualEnvironment, Environment, EnvironmentMode } from '../../entities';
import type { MapBy } from '../../types';
import type { InitializerOptions } from './types';
import type { ContextualEnvironment, Environment, EnvironmentMode } from '../../entities/index.js';
import type { MapBy } from '../../types.js';
import type { InitializerOptions } from './types.js';

export type EnvironmentInitializer<T, OPTIONS extends InitializerOptions = InitializerOptions> = (
options: OPTIONS,
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/com/initializers/iframe.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Communication } from '../communication';
import type { InitializerOptions } from './types';
import { WindowInitializerService } from '../window-initializer-service';
import type { Communication } from '../communication.js';
import type { InitializerOptions } from './types.js';
import { WindowInitializerService } from '../window-initializer-service.js';

export const INSTANCE_ID_PARAM_NAME = 'iframe-instance-id';
export interface IIframeInitializerOptions {
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/com/initializers/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export * from './socket-server';
export * from './window';
export * from './contextual';
export * from './webworker';
export * from './iframe';
export * from './ipc';
export * from './types';
export * from './socket-server.js';
export * from './window.js';
export * from './contextual.js';
export * from './webworker.js';
export * from './iframe.js';
export * from './ipc.js';
export * from './types.js';
2 changes: 1 addition & 1 deletion packages/core/src/com/initializers/ipc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { InitializerOptions } from './types';
import type { InitializerOptions } from './types.js';

export const ipcInitializer = async ({ communication, env: { env, endpointType } }: InitializerOptions) => {
const instanceId = communication.getEnvironmentInstanceId(env, endpointType);
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/com/initializers/socket-server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { SocketOptions } from 'socket.io-client';
import { WsClientHost } from '../hosts/ws-client-host';
import type { ReadyMessage } from '../message-types';
import type { InitializerOptions } from './types';
import { WsClientHost } from '../hosts/ws-client-host.js';
import type { ReadyMessage } from '../message-types.js';
import type { InitializerOptions } from './types.js';

export interface SocketClientInitializerOptions extends InitializerOptions, Partial<SocketOptions> {}

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/com/initializers/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Environment } from '../../entities';
import type { Communication } from '../communication';
import type { Environment } from '../../entities/index.js';
import type { Communication } from '../communication.js';

export interface InitializerOptions {
communication: Communication;
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/com/initializers/webworker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Worker } from '@wixc3/isomorphic-worker/worker';

import { UniversalWorkerHost } from '../hosts/universal-worker-host';
import type { InitializerOptions } from './types';
import { UniversalWorkerHost } from '../hosts/universal-worker-host.js';
import type { InitializerOptions } from './types.js';

export async function webWorkerInitializer({ communication, env: { env, endpointType } }: InitializerOptions) {
const isSingleton = endpointType === 'single';
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/com/initializers/window.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { WindowHost } from '../types';
import { isIframe } from '../helpers';
import { injectScript } from '../../helpers';
import type { InitializerOptions } from './types';
import type { WindowHost } from '../types.js';
import { isIframe } from '../helpers.js';
import { injectScript } from '../../helpers/index.js';
import type { InitializerOptions } from './types.js';

interface WindowInitializerOptions extends InitializerOptions {
host?: WindowHost;
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/com/logger-service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { LogMessage, LogMetadata } from '../common-types';
import type { LogMessage, LogMetadata } from '../common-types.js';
import { EventEmitter } from '@wixc3/patterns';
import { LoggerTransport, LogLevel } from '../types';
import { type LoggerTransport, LogLevel } from '../types.js';

export interface LogValueData {
value: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/com/message-types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SerializableArguments } from './types';
import type { SerializableArguments } from './types.js';

export interface RemoteCallAddress {
api: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/com/service-config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AnyFunction, FilterFirstArgument, ValuePromise } from './types';
import type { AnyFunction, FilterFirstArgument, ValuePromise } from './types.js';

export function multiTenantMethod<T extends AnyFunction>(method: T) {
return (context: any) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/com/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SERVICE_CONFIG } from '../symbols';
import { SERVICE_CONFIG } from '../symbols.js';

export type SerializableArguments = unknown[];
export type SerializableMethod = (...args: SerializableArguments) => void;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/common-types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { LogLevel } from './types';
import type { LogLevel } from './types.js';

export interface LogMetadata {
[key: string]: unknown;
Expand Down
24 changes: 12 additions & 12 deletions packages/core/src/communication.feature.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { BaseHost } from './com/hosts/base-host';
import { Communication, ConfigEnvironmentRecord, CommunicationOptions } from './com/communication';
import { LoggerService } from './com/logger-service';
import type { Target } from './com/types';
import { Config } from './entities/config';
import { AllEnvironments, Universal } from './entities/env';
import { Feature } from './entities/feature';
import { Value } from './entities/value';
import { Slot } from './entities/slot';
import { RUN_OPTIONS, ENGINE } from './symbols';
import { LoggerTransport, LogLevel } from './types';
import { WindowInitializerService } from './com/window-initializer-service';
import { BaseHost } from './com/hosts/base-host.js';
import { Communication, type ConfigEnvironmentRecord, type CommunicationOptions } from './com/communication.js';
import { LoggerService } from './com/logger-service.js';
import type { Target } from './com/types.js';
import { Config } from './entities/config.js';
import { AllEnvironments, Universal } from './entities/env.js';
import { Feature } from './entities/feature.js';
import { Value } from './entities/value.js';
import { Slot } from './entities/slot.js';
import { RUN_OPTIONS, ENGINE } from './symbols.js';
import { type LoggerTransport, LogLevel } from './types.js';
import { WindowInitializerService } from './com/window-initializer-service.js';
export interface IComConfig {
id?: string;
host?: Target;
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/entities/config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { RuntimeEngine } from '../runtime-engine';
import { CONFIGURABLE, CREATE_RUNTIME, REGISTER_VALUE } from '../symbols';
import type { EnvVisibility } from '../types';
import { AllEnvironments, Environment } from './env';
import { FeatureInput } from './input';
import type { RuntimeEngine } from '../runtime-engine.js';
import { CONFIGURABLE, CREATE_RUNTIME, REGISTER_VALUE } from '../symbols.js';
import type { EnvVisibility } from '../types.js';
import { AllEnvironments, Environment } from './env.js';
import { FeatureInput } from './input.js';

export type MergeConfigHook<T extends object> = (a: Readonly<T>, b: Readonly<Partial<T>>) => T;

Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/entities/env.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { EnvironmentTypes } from '../com/types';
import { runtimeType } from '../entity-helpers';
import type { Context, EnvVisibility, MapBy } from '../types';
import type { EnvironmentTypes } from '../com/types.js';
import { runtimeType } from '../entity-helpers.js';
import type { Context, EnvVisibility, MapBy } from '../types.js';

export type EnvironmentMode = 'single' | 'multi';
export type AnyEnvironment = Environment<
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/entities/feature.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SetMultiMap } from '@wixc3/patterns';
import type { RuntimeEngine } from '../runtime-engine';
import { ENGINE, IDENTIFY_API, RUN_OPTIONS } from '../symbols';
import type { RuntimeEngine } from '../runtime-engine.js';
import { ENGINE, IDENTIFY_API, RUN_OPTIONS } from '../symbols.js';
import type {
Context,
DeepEnvironmentDeps,
Expand All @@ -19,8 +19,8 @@ import type {
PartialFeatureConfig,
RegisteringFeature,
RunningInstance,
} from '../types';
import type { AnyEnvironment, GloballyProvidingEnvironments } from './env';
} from '../types.js';
import type { AnyEnvironment, GloballyProvidingEnvironments } from './env.js';

// this makes the constructor kind of private
const instantiateFeatureSymbol = Symbol('instantiateFeature');
Expand Down
20 changes: 10 additions & 10 deletions packages/core/src/entities/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export * from './config';
export * from './env';
export * from './input';
export * from './map-slot';
export * from './ordered-slot';
export * from './output';
export * from './service';
export * from './slot';
export * from './feature';
export * from './value';
export * from './config.js';
export * from './env.js';
export * from './input.js';
export * from './map-slot.js';
export * from './ordered-slot.js';
export * from './output.js';
export * from './service.js';
export * from './slot.js';
export * from './feature.js';
export * from './value.js';
8 changes: 4 additions & 4 deletions packages/core/src/entities/input.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { runtimeType } from '../entity-helpers';
import type { RuntimeEngine } from '../runtime-engine';
import { CREATE_RUNTIME, REGISTER_VALUE } from '../symbols';
import type { Entity, EnvVisibility } from '../types';
import { runtimeType } from '../entity-helpers.js';
import type { RuntimeEngine } from '../runtime-engine.js';
import { CREATE_RUNTIME, REGISTER_VALUE } from '../symbols.js';
import type { Entity, EnvVisibility } from '../types.js';

export abstract class FeatureInput<
Type,
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/entities/map-slot.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CREATE_RUNTIME } from '../symbols';
import type { EnvVisibility } from '../types';
import { FeatureInput } from './input';
import { CREATE_RUNTIME } from '../symbols.js';
import type { EnvVisibility } from '../types.js';
import { FeatureInput } from './input.js';

export class MapRegistry<K, T> {
private items: Map<K, T> = new Map<K, T>();
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/entities/ordered-slot.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CREATE_RUNTIME } from '../symbols';
import type { EnvVisibility } from '../types';
import { FeatureInput } from './input';
import { CREATE_RUNTIME } from '../symbols.js';
import type { EnvVisibility } from '../types.js';
import { FeatureInput } from './input.js';

type Param<T, K extends keyof T> = K extends any ? [K, boolean | Array<T[K]>] : never;

Expand Down
Loading

0 comments on commit aed4aaf

Please sign in to comment.