Skip to content

Commit

Permalink
🚚 rename 'global' to 'publicApi' when it makes more sense
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitZugmeyer committed Jan 6, 2021
1 parent c03dad4 commit 6db1bca
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 100 deletions.
8 changes: 4 additions & 4 deletions packages/core/src/boot/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { areCookiesAuthorized, CookieOptions } from '../browser/cookie'
import { buildConfiguration, UserConfiguration } from '../domain/configuration'
import { setDebugMode, startInternalMonitoring } from '../domain/internalMonitoring'

export function makeGlobal<T>(stub: T): T & { onReady(callback: () => void): void } {
const global = {
export function makePublicApi<T>(stub: T): T & { onReady(callback: () => void): void } {
const publicApi = {
...stub,

// This API method is intentionally not monitored, since the only thing executed is the
Expand All @@ -16,14 +16,14 @@ export function makeGlobal<T>(stub: T): T & { onReady(callback: () => void): voi

// Add an "hidden" property to set debug mode. We define it that way to hide it
// as much as possible but of course it's not a real protection.
Object.defineProperty(global, '_setDebug', {
Object.defineProperty(publicApi, '_setDebug', {
get() {
return setDebugMode
},
enumerable: false,
})

return global
return publicApi
}

export function defineGlobal<Global, Name extends keyof Global>(global: Global, name: Name, api: Global[Name]) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export {
BuildMode,
Datacenter,
defineGlobal,
makeGlobal,
makePublicApi,
commonInit,
checkCookiesAuthorized,
checkIsNotLocalFile,
Expand Down
18 changes: 9 additions & 9 deletions packages/logs/src/boot/logs.entry.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Context, monitor, ONE_SECOND } from '@datadog/browser-core'

import { HandlerType, LogsMessage, StatusType } from '../domain/logger'
import { LogsGlobal, makeLogsGlobal, StartLogs } from './logs.entry'
import { LogsPublicApi, makeLogsPublicApi, StartLogs } from './logs.entry'

const DEFAULT_INIT_CONFIGURATION = { clientToken: 'xxx' }

Expand All @@ -28,17 +28,17 @@ describe('logs entry', () => {
startLogsGetGlobalContext = undefined
})

it('should set global with init', () => {
const LOGS = makeLogsGlobal(startLogs)
it('should define the public API with init', () => {
const LOGS = makeLogsPublicApi(startLogs)
expect(!!LOGS).toEqual(true)
expect(!!LOGS.init).toEqual(true)
})

describe('configuration validation', () => {
let LOGS: LogsGlobal
let LOGS: LogsPublicApi

beforeEach(() => {
LOGS = makeLogsGlobal(startLogs)
LOGS = makeLogsPublicApi(startLogs)
})

it('init should log an error with no public api key', () => {
Expand Down Expand Up @@ -123,10 +123,10 @@ describe('logs entry', () => {
})

describe('pre-init API usages', () => {
let LOGS: LogsGlobal
let LOGS: LogsPublicApi

beforeEach(() => {
LOGS = makeLogsGlobal(startLogs)
LOGS = makeLogsPublicApi(startLogs)
jasmine.clock().install()
jasmine.clock().mockDate()
})
Expand Down Expand Up @@ -196,10 +196,10 @@ describe('logs entry', () => {
})

describe('post-init API usages', () => {
let LOGS: LogsGlobal
let LOGS: LogsPublicApi

beforeEach(() => {
LOGS = makeLogsGlobal(startLogs)
LOGS = makeLogsPublicApi(startLogs)
LOGS.init(DEFAULT_INIT_CONFIGURATION)
})

Expand Down
12 changes: 6 additions & 6 deletions packages/logs/src/boot/logs.entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
defineGlobal,
getGlobalObject,
isPercentage,
makeGlobal,
makePublicApi,
monitor,
UserConfiguration,
} from '@datadog/browser-core'
Expand All @@ -26,18 +26,18 @@ export interface LoggerConfiguration {
context?: object
}

export type LogsGlobal = ReturnType<typeof makeLogsGlobal>
export type LogsPublicApi = ReturnType<typeof makeLogsPublicApi>

export const datadogLogs = makeLogsGlobal(startLogs)
export const datadogLogs = makeLogsPublicApi(startLogs)

interface BrowserWindow extends Window {
DD_LOGS?: LogsGlobal
DD_LOGS?: LogsPublicApi
}
defineGlobal(getGlobalObject<BrowserWindow>(), 'DD_LOGS', datadogLogs)

export type StartLogs = typeof startLogs

export function makeLogsGlobal(startLogsImpl: StartLogs) {
export function makeLogsPublicApi(startLogsImpl: StartLogs) {
let isAlreadyInitialized = false

const globalContextManager = createContextManager()
Expand All @@ -49,7 +49,7 @@ export function makeLogsGlobal(startLogsImpl: StartLogs) {
}
const logger = new Logger(sendLog)

return makeGlobal({
return makePublicApi({
logger,

init: monitor((userConfiguration: LogsUserConfiguration) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/logs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { Logger, LogsMessage, StatusType, HandlerType } from './domain/logger'
export { LogsUserConfiguration, LoggerConfiguration, LogsGlobal, datadogLogs } from './boot/logs.entry'
export { LogsUserConfiguration, LoggerConfiguration, LogsPublicApi as LogsGlobal, datadogLogs } from './boot/logs.entry'
export { LogsEvent } from './logsEvent.types'
2 changes: 1 addition & 1 deletion packages/rum-core/src/boot/rum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { CommonContext } from '../rawRumEvent.types'
import { startRumBatch } from '../transport/batch'

import { buildEnv } from './buildEnv'
import { RumUserConfiguration } from './rum.entry'
import { RumUserConfiguration } from './rumPublicApi'

export function startRum(userConfiguration: RumUserConfiguration, getCommonContext: () => CommonContext) {
const lifeCycle = new LifeCycle()
Expand Down
Loading

0 comments on commit 6db1bca

Please sign in to comment.