Skip to content

Commit

Permalink
fix: adapt for Secret
Browse files Browse the repository at this point in the history
  • Loading branch information
patroza committed Dec 6, 2023
1 parent de1cd1c commit 2f73b6b
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 64 deletions.
40 changes: 20 additions & 20 deletions packages/core/vendor/effect-io-tsplus.json
Original file line number Diff line number Diff line change
Expand Up @@ -2750,43 +2750,43 @@
]
}
],
"effect/ConfigSecret": [
"effect/Secret": [
{
"definitionName": "ConfigSecret",
"definitionName": "Secret",
"definitionKind": "interface",
"extensions": [
{
"kind": "type",
"typeName": "effect/io/ConfigSecret"
"typeName": "effect/io/Secret"
},
{
"kind": "companion",
"typeName": "effect/io/ConfigSecret.Ops"
"typeName": "effect/io/Secret.Ops"
}
]
},
{
"definitionName": "ConfigSecretTypeId",
"definitionName": "SecretTypeId",
"definitionKind": "type",
"extensions": [
{
"kind": "type",
"typeName": "effect/io/ConfigSecret.TypeId"
"typeName": "effect/io/Secret.TypeId"
},
{
"kind": "companion",
"typeName": "effect/io/ConfigSecret.TypeId.Ops"
"typeName": "effect/io/Secret.TypeId.Ops"
}
]
},
{
"definitionName": "ConfigSecretTypeId",
"definitionName": "SecretTypeId",
"definitionKind": "const",
"extensions": [
{
"kind": "static",
"typeName": "effect/io/ConfigSecret.TypeId.Ops",
"name": "ConfigSecretTypeId"
"typeName": "effect/io/Secret.TypeId.Ops",
"name": "SecretTypeId"
}
]
},
Expand All @@ -2796,7 +2796,7 @@
"extensions": [
{
"kind": "static",
"typeName": "effect/io/ConfigSecret.Ops",
"typeName": "effect/io/Secret.Ops",
"name": "fromChunk"
}
]
Expand All @@ -2807,19 +2807,19 @@
"extensions": [
{
"kind": "static",
"typeName": "effect/io/ConfigSecret.Ops",
"typeName": "effect/io/Secret.Ops",
"name": "fromString"
}
]
},
{
"definitionName": "isConfigSecret",
"definitionName": "isSecret",
"definitionKind": "const",
"extensions": [
{
"kind": "static",
"typeName": "effect/io/ConfigSecret.Ops",
"name": "isConfigSecret"
"typeName": "effect/io/Secret.Ops",
"name": "isSecret"
}
]
},
Expand All @@ -2829,7 +2829,7 @@
"extensions": [
{
"kind": "static",
"typeName": "effect/io/ConfigSecret.Ops",
"typeName": "effect/io/Secret.Ops",
"name": "make"
}
]
Expand All @@ -2840,12 +2840,12 @@
"extensions": [
{
"kind": "getter",
"typeName": "effect/io/ConfigSecret",
"typeName": "effect/io/Secret",
"name": "unsafeWipe"
},
{
"kind": "static",
"typeName": "effect/io/ConfigSecret.Ops",
"typeName": "effect/io/Secret.Ops",
"name": "unsafeWipe"
}
]
Expand All @@ -2856,12 +2856,12 @@
"extensions": [
{
"kind": "getter",
"typeName": "effect/io/ConfigSecret",
"typeName": "effect/io/Secret",
"name": "value"
},
{
"kind": "static",
"typeName": "effect/io/ConfigSecret.Ops",
"typeName": "effect/io/Secret.Ops",
"name": "value"
}
]
Expand Down
2 changes: 1 addition & 1 deletion packages/infra/_src/services/Emailer/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface SendgridConfig {
subjectPrefix: string
realMail: boolean
defaultFrom: Email | { name?: NonEmptyString255; email: Email }
apiKey: ConfigSecret
apiKey: Secret
}
export type EmailMsg = sgMail.MailDataRequired
export type EmailTemplateMsg = MailData & { templateId: string }
Expand Down
2 changes: 1 addition & 1 deletion packages/infra/_src/services/Store/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export interface PersistenceModelType<Id extends string> {
}

export interface StorageConfig {
url: ConfigSecret
url: Secret
prefix: string
dbName: string
}
46 changes: 23 additions & 23 deletions packages/prelude/_src/Config/SecretURL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,98 +2,98 @@
* @since 1.0.0
*/
import type * as Chunk from "effect/Chunk"
import type { ConfigSecretTypeId } from "effect/ConfigSecret"
import type { SecretTypeId } from "effect/Secret"
import type * as Equal from "effect/Equal"
import * as internal from "./internal/configSecretURL.js"

// /**
// * @since 1.0.0
// * @category symbols
// */
// export const ConfigSecretURLTypeId: unique symbol = internal.ConfigSecretURLTypeId
// export const SecretURLTypeId: unique symbol = internal.SecretURLTypeId

// /**
// * @since 1.0.0
// * @category symbols
// */
// export type ConfigSecretURLTypeId = typeof ConfigSecretURLTypeId
// export type SecretURLTypeId = typeof SecretURLTypeId

/**
* @tsplus type ConfigSecretURL
* @tsplus type SecretURL
* @since 1.0.0
* @category models
*/
export interface ConfigSecretURL extends ConfigSecretURL.Proto, Equal.Equal {
export interface SecretURL extends SecretURL.Proto, Equal.Equal {
/** @internal */
readonly raw: Array<number>
}

/**
* @tsplus type ConfigSecretURL.Ops
* @tsplus type SecretURL.Ops
*/
export interface ConfigSecretURLOps {}
export interface SecretURLOps {}

export const ConfigSecretURL: ConfigSecretURLOps = {}
export const SecretURL: SecretURLOps = {}

/**
* @since 1.0.0
*/
export declare namespace ConfigSecretURL {
export declare namespace SecretURL {
/**
* @since 1.0.0
* @category models
*/
export interface Proto {
readonly [ConfigSecretTypeId]: ConfigSecretTypeId
readonly [SecretTypeId]: SecretTypeId
}
}

/**
* @tsplus static ConfigSecretURL.Ops isConfigSecretURL
* @tsplus static SecretURL.Ops isSecretURL
* @since 1.0.0
* @category refinements
*/
export const isConfigSecretURL: (u: unknown) => u is ConfigSecretURL = internal.isConfigSecretURL
export const isSecretURL: (u: unknown) => u is SecretURL = internal.isSecretURL

/**
* @tsplus static ConfigSecretURL.Ops make
* @tsplus static SecretURL.Ops make
* @since 1.0.0
* @category constructors
*/
export const make: (bytes: Array<number>) => ConfigSecretURL = internal.make
export const make: (bytes: Array<number>) => SecretURL = internal.make

/**
* @tsplus static ConfigSecretURL.Ops fromChunk
* @tsplus static SecretURL.Ops fromChunk
* @since 1.0.0
* @category constructors
*/
export const fromChunk: (chunk: Chunk.Chunk<string>) => ConfigSecretURL = internal.fromChunk
export const fromChunk: (chunk: Chunk.Chunk<string>) => SecretURL = internal.fromChunk

/**
* @tsplus static ConfigSecretURL.Ops fromString
* @tsplus static SecretURL.Ops fromString
* @since 1.0.0
* @category constructors
*/
export const fromString: (text: string) => ConfigSecretURL = internal.fromString
export const fromString: (text: string) => SecretURL = internal.fromString

/**
* @tsplus getter ConfigSecretURL value
* @tsplus getter SecretURL value
* @since 1.0.0
* @category getters
*/
export const value: (self: ConfigSecretURL) => string = internal.value
export const value: (self: SecretURL) => string = internal.value

/**
* @tsplus fluent ConfigSecretURL unsafeWipe
* @tsplus fluent SecretURL unsafeWipe
* @since 1.0.0
* @category unsafe
*/
export const unsafeWipe: (self: ConfigSecretURL) => void = internal.unsafeWipe
export const unsafeWipe: (self: SecretURL) => void = internal.unsafeWipe

/**
* @tsplus static effect/io/Config.Ops secretURL
*/
export const secretURL = (name?: string): Config<ConfigSecretURL> => {
export const secretURL = (name?: string): Config<SecretURL> => {
const config = Config.primitive(
"a secret property",
(text) => Either(fromString(text))
Expand Down
34 changes: 17 additions & 17 deletions packages/prelude/_src/Config/internal/configSecretURL.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import * as Chunk from "effect/Chunk"
import { ConfigSecretTypeId } from "effect/ConfigSecret"
import { SecretTypeId } from "effect/Secret"
import * as EQ from "effect/Equal"
import { pipe } from "effect/Function"
import * as Hash from "effect/Hash"
import type * as ConfigSecretURL from "../SecretURL.js"
import type * as SecretURL from "../SecretURL.js"

/** @internal */
const ConfigSecretURLSymbolKey = "effect/ConfigSecret" // "@effect-app/prelude/COnfigSecretURL"
const SecretURLSymbolKey = "effect/Secret" // "@effect-app/prelude/COnfigSecretURL"

/** @internal */
export const proto = {
[ConfigSecretTypeId]: ConfigSecretTypeId,
[Hash.symbol](this: ConfigSecretURL.ConfigSecretURL): number {
[SecretTypeId]: SecretTypeId,
[Hash.symbol](this: SecretURL.SecretURL): number {
return pipe(
Hash.hash(ConfigSecretURLSymbolKey),
Hash.hash(SecretURLSymbolKey),
Hash.combine(Hash.hash(this.raw))
)
},
[EQ.symbol](this: ConfigSecretURL.ConfigSecretURL, that: unknown): boolean {
return isConfigSecretURL(that) && Equal.equals(this.raw, that.raw)
[EQ.symbol](this: SecretURL.SecretURL, that: unknown): boolean {
return isSecretURL(that) && Equal.equals(this.raw, that.raw)
}
}

/** @internal */
export const isConfigSecretURL = (u: unknown): u is ConfigSecretURL.ConfigSecretURL => {
return typeof u === "object" && u != null && ConfigSecretTypeId in u
export const isSecretURL = (u: unknown): u is SecretURL.SecretURL => {
return typeof u === "object" && u != null && SecretTypeId in u
}

/** @internal */
export const make = (bytes: Array<number>): ConfigSecretURL.ConfigSecretURL => {
export const make = (bytes: Array<number>): SecretURL.SecretURL => {
const secret = Object.create(proto)
let protocol = "unknown"
try {
Expand All @@ -44,15 +44,15 @@ export const make = (bytes: Array<number>): ConfigSecretURL.ConfigSecretURL => {
enumerable: false,
value() {
return ({
_tag: "ConfigSecretURL",
_tag: "SecretURL",
protocol
})
}
})
Object.defineProperty(secret, "toString", {
enumerable: false,
value() {
return `ConfigSecretURL(${protocol}://<redacted>)`
return `SecretURL(${protocol}://<redacted>)`
}
})
Object.defineProperty(secret, "raw", {
Expand All @@ -63,22 +63,22 @@ export const make = (bytes: Array<number>): ConfigSecretURL.ConfigSecretURL => {
}

/** @internal */
export const fromChunk = (chunk: Chunk.Chunk<string>): ConfigSecretURL.ConfigSecretURL => {
export const fromChunk = (chunk: Chunk.Chunk<string>): SecretURL.SecretURL => {
return make(Chunk.toReadonlyArray(chunk).map((char) => char.charCodeAt(0)))
}

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

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

/** @internal */
export const unsafeWipe = (self: ConfigSecretURL.ConfigSecretURL): void => {
export const unsafeWipe = (self: SecretURL.SecretURL): void => {
for (let i = 0; i < self.raw.length; i++) {
self.raw[i] = 0
}
Expand Down
4 changes: 2 additions & 2 deletions packages/prelude/_src/_global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import { Config } from "effect/Config"
/**
* @tsplus global
*/
import { ConfigSecretURL } from "@effect-app/prelude/Config/SecretURL"
import { SecretURL } from "@effect-app/prelude/Config/SecretURL"

/**
* @tsplus global
*/
import { ConfigSecret } from "effect/ConfigSecret"
import { Secret } from "effect/Secret"

/**
* @tsplus global
Expand Down

0 comments on commit 2f73b6b

Please sign in to comment.