Skip to content

Commit

Permalink
feat(type): define alwatrRegistredList
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm committed Dec 29, 2022
1 parent 8cf93c4 commit 25406c2
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 37 deletions.
8 changes: 2 additions & 6 deletions core/logger/src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import {alwatrRegisteredList} from '@alwatr/type';

import type {AlwatrLogger} from './type.js';
export {AlwatrLogger};

const isBrowser = typeof process === 'undefined';

/**
* Define `globalThis.Alwatr.registeredList`
*/
export const alwatrRegisteredList = globalThis.Alwatr?.registeredList || [];
globalThis.Alwatr ??= {version: '0.26.0', registeredList: alwatrRegisteredList};

alwatrRegisteredList.push({
name: '@alwatr/logger',
version: '{{ALWATR_VERSION}}', // TODO: replace with real version at release time.
Expand Down
29 changes: 0 additions & 29 deletions core/logger/src/type.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,3 @@
/* eslint-disable no-var */
export interface GlobalAlwatr {
version: string;
registeredList: Array<{
name: string;
version: string;
}>;
}

declare global {
var Alwatr: GlobalAlwatr;
var ALWATR_DEBUG: string | undefined;

/**
* @TODO: Make an issue to TS, WTF is this way! any better solution for more args in bind?!
*/
interface CallableFunction {
bind<T, A0, A1, A2, A3, A4, A extends unknown[], R>(
this: (this: T, arg0: A0, arg1: A1, arg2: A2, arg3: A3, arg4: A4, ...args: A) => R,
thisArg: T,
arg0: A0,
arg1: A1,
arg2: A2,
arg3: A3,
arg4: A4
): (...args: A) => R;
}
}

export interface AlwatrLogger {
/**
* Debug state for current scope base on localStorage `ALWATR_LOG` pattern.
Expand Down
4 changes: 2 additions & 2 deletions core/storage-client/src/storage-client.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {serviceRequest} from '@alwatr/fetch';
import {alwatrRegisteredList, createLogger} from '@alwatr/logger';
import {createLogger} from '@alwatr/logger';
import {AlwatrDocumentObject, AlwatrDocumentStorage, alwatrRegisteredList} from '@alwatr/type';

import type {AlwatrStorageClientConfig} from './type.js';
import type {FetchOptions} from '@alwatr/fetch';
import type {AlwatrDocumentObject, AlwatrDocumentStorage} from '@alwatr/type';

export {AlwatrStorageClientConfig};

Expand Down
34 changes: 34 additions & 0 deletions core/type/src/alwatr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* eslint-disable no-var */
export interface GlobalAlwatr {
version: string;
registeredList: Array<{
name: string;
version: string;
}>;
}

declare global {
var Alwatr: GlobalAlwatr;
var ALWATR_DEBUG: string | undefined;

/**
* @TODO: Make an issue to TS, WTF is this way! any better solution for more args in bind?!
*/
interface CallableFunction {
bind<T, A0, A1, A2, A3, A4, A extends unknown[], R>(
this: (this: T, arg0: A0, arg1: A1, arg2: A2, arg3: A3, arg4: A4, ...args: A) => R,
thisArg: T,
arg0: A0,
arg1: A1,
arg2: A2,
arg3: A3,
arg4: A4
): (...args: A) => R;
}
}

/**
* Define `globalThis.Alwatr.registeredList`
*/
export const alwatrRegisteredList = globalThis.Alwatr?.registeredList || [];
globalThis.Alwatr ??= {version: '0.26.0', registeredList: alwatrRegisteredList};
1 change: 1 addition & 0 deletions core/type/src/type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './storage.js';
export * from './service.js';
export * from './alwatr.js';

// FIXME:
export type MaybePromise<T> = T | Promise<T>

0 comments on commit 25406c2

Please sign in to comment.