Skip to content

Commit

Permalink
Rename ConfigSecret to Secret (#1745)
Browse files Browse the repository at this point in the history
  • Loading branch information
IMax153 authored Dec 6, 2023
1 parent 7c31299 commit c142caa
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 172 deletions.
5 changes: 5 additions & 0 deletions .changeset/weak-tables-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

rename ConfigSecret to Secret
4 changes: 2 additions & 2 deletions src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
import type * as Chunk from "./Chunk.js"
import type * as ConfigError from "./ConfigError.js"
import type * as ConfigSecret from "./ConfigSecret.js"
import type * as Either from "./Either.js"
import type { LazyArg } from "./Function.js"
import type * as HashMap from "./HashMap.js"
Expand All @@ -13,6 +12,7 @@ import type * as LogLevel from "./LogLevel.js"
import type * as Option from "./Option.js"
import type { Pipeable } from "./Pipeable.js"
import type { Predicate, Refinement } from "./Predicate.js"
import type * as Secret from "./Secret.js"
import type * as Types from "./Types.js"

/**
Expand Down Expand Up @@ -300,7 +300,7 @@ export const repeat: <A>(self: Config<A>) => Config<Array<A>> = internal.repeat
* @since 2.0.0
* @category constructors
*/
export const secret: (name?: string) => Config<ConfigSecret.ConfigSecret> = internal.secret
export const secret: (name?: string) => Config<Secret.Secret> = internal.secret

/**
* Constructs a config for a sequence of values.
Expand Down
76 changes: 0 additions & 76 deletions src/ConfigSecret.ts

This file was deleted.

75 changes: 75 additions & 0 deletions src/Secret.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* @since 2.0.0
*/
import type * as Equal from "./Equal.js"
import * as InternalSecret from "./internal/secret.js"

/**
* @since 2.0.0
* @category symbols
*/
export const SecretTypeId: unique symbol = InternalSecret.SecretTypeId

/**
* @since 2.0.0
* @category symbols
*/
export type SecretTypeId = typeof SecretTypeId

/**
* @since 2.0.0
* @category models
*/
export interface Secret extends Secret.Proto, Equal.Equal {
/** @internal */
readonly raw: Array<number>
}

/**
* @since 2.0.0
*/
export declare namespace Secret {
/**
* @since 2.0.0
* @category models
*/
export interface Proto {
readonly [SecretTypeId]: SecretTypeId
}
}

/**
* @since 2.0.0
* @category refinements
*/
export const isSecret: (u: unknown) => u is Secret = InternalSecret.isSecret

/**
* @since 2.0.0
* @category constructors
*/
export const make: (bytes: Array<number>) => Secret = InternalSecret.make

/**
* @since 2.0.0
* @category constructors
*/
export const fromIterable: (iterable: Iterable<string>) => Secret = InternalSecret.fromIterable

/**
* @since 2.0.0
* @category constructors
*/
export const fromString: (text: string) => Secret = InternalSecret.fromString

/**
* @since 2.0.0
* @category getters
*/
export const value: (self: Secret) => string = InternalSecret.value

/**
* @since 2.0.0
* @category unsafe
*/
export const unsafeWipe: (self: Secret) => void = InternalSecret.unsafeWipe
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,6 @@ export * as ConfigProvider from "./ConfigProvider.js"
*/
export * as ConfigProviderPathPatch from "./ConfigProviderPathPatch.js"

/**
* @since 2.0.0
*/
export * as ConfigSecret from "./ConfigSecret.js"

/**
* @since 2.0.0
*/
Expand Down Expand Up @@ -643,6 +638,11 @@ export * as ScopedCache from "./ScopedCache.js"
*/
export * as ScopedRef from "./ScopedRef.js"

/**
* @since 2.0.0
*/
export * as Secret from "./Secret.js"

/**
* @since 2.0.0
*/
Expand Down
8 changes: 4 additions & 4 deletions src/internal/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as Chunk from "../Chunk.js"
import type * as Config from "../Config.js"
import * as ConfigError from "../ConfigError.js"
import type * as ConfigSecret from "../ConfigSecret.js"
import * as Either from "../Either.js"
import type { LazyArg } from "../Function.js"
import { constTrue, dual, pipe } from "../Function.js"
Expand All @@ -11,10 +10,11 @@ import type * as LogLevel from "../LogLevel.js"
import * as Option from "../Option.js"
import { pipeArguments } from "../Pipeable.js"
import { hasProperty, type Predicate, type Refinement } from "../Predicate.js"
import type * as Secret from "../Secret.js"
import * as configError from "./configError.js"
import * as configSecret from "./configSecret.js"
import * as core from "./core.js"
import * as OpCodes from "./opCodes/config.js"
import * as InternalSecret from "./secret.js"

const ConfigSymbolKey = "effect/Config"

Expand Down Expand Up @@ -380,10 +380,10 @@ export const repeat = <A>(self: Config.Config<A>): Config.Config<Array<A>> => {
}

/** @internal */
export const secret = (name?: string): Config.Config<ConfigSecret.ConfigSecret> => {
export const secret = (name?: string): Config.Config<Secret.Secret> => {
const config = primitive(
"a secret property",
(text) => Either.right(configSecret.fromString(text))
(text) => Either.right(InternalSecret.fromString(text))
)
return name === undefined ? config : nested(config, name)
}
Expand Down
70 changes: 0 additions & 70 deletions src/internal/configSecret.ts

This file was deleted.

69 changes: 69 additions & 0 deletions src/internal/secret.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import * as Equal from "../Equal.js"
import { pipe } from "../Function.js"
import * as Hash from "../Hash.js"
import { hasProperty } from "../Predicate.js"
import * as ReadonlyArray from "../ReadonlyArray.js"
import type * as Secret from "../Secret.js"

/** @internal */
const SecretSymbolKey = "effect/Secret"

/** @internal */
export const SecretTypeId: Secret.SecretTypeId = Symbol.for(
SecretSymbolKey
) as Secret.SecretTypeId

/** @internal */
export const proto = {
[SecretTypeId]: SecretTypeId,
[Hash.symbol](this: Secret.Secret): number {
return pipe(
Hash.hash(SecretSymbolKey),
Hash.combine(Hash.array(this.raw))
)
},
[Equal.symbol](this: Secret.Secret, that: unknown): boolean {
return isSecret(that) && this.raw.length === that.raw.length &&
this.raw.every((v, i) => Equal.equals(v, that.raw[i]))
}
}

/** @internal */
export const isSecret = (u: unknown): u is Secret.Secret => hasProperty(u, SecretTypeId)

/** @internal */
export const make = (bytes: Array<number>): Secret.Secret => {
const secret = Object.create(proto)
Object.defineProperty(secret, "toString", {
enumerable: false,
value() {
return "Secret(<redacted>)"
}
})
Object.defineProperty(secret, "raw", {
enumerable: false,
value: bytes
})
return secret
}

/** @internal */
export const fromIterable = (iterable: Iterable<string>): Secret.Secret =>
make(ReadonlyArray.fromIterable(iterable).map((char) => char.charCodeAt(0)))

/** @internal */
export const fromString = (text: string): Secret.Secret => {
return make(text.split("").map((char) => char.charCodeAt(0)))
}

/** @internal */
export const value = (self: Secret.Secret): string => {
return self.raw.map((byte) => String.fromCharCode(byte)).join("")
}

/** @internal */
export const unsafeWipe = (self: Secret.Secret): void => {
for (let i = 0; i < self.raw.length; i++) {
self.raw[i] = 0
}
}
Loading

0 comments on commit c142caa

Please sign in to comment.