effect 4.0.0-beta.4 → 4.0.0-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (310) hide show
  1. package/dist/Cause.d.ts +1 -1
  2. package/dist/Cause.d.ts.map +1 -1
  3. package/dist/Channel.d.ts.map +1 -1
  4. package/dist/Channel.js +6 -4
  5. package/dist/Channel.js.map +1 -1
  6. package/dist/Config.d.ts +1 -1
  7. package/dist/Data.d.ts +3 -2
  8. package/dist/Data.d.ts.map +1 -1
  9. package/dist/Data.js +9 -8
  10. package/dist/Data.js.map +1 -1
  11. package/dist/Effect.d.ts +0 -226
  12. package/dist/Effect.d.ts.map +1 -1
  13. package/dist/Effect.js +0 -118
  14. package/dist/Effect.js.map +1 -1
  15. package/dist/Encoding.d.ts +194 -0
  16. package/dist/Encoding.d.ts.map +1 -0
  17. package/dist/Encoding.js +352 -0
  18. package/dist/Encoding.js.map +1 -0
  19. package/dist/Equal.js.map +1 -1
  20. package/dist/FileSystem.d.ts +1 -1
  21. package/dist/FileSystem.d.ts.map +1 -1
  22. package/dist/FileSystem.js +5 -5
  23. package/dist/FileSystem.js.map +1 -1
  24. package/dist/Filter.d.ts +30 -1
  25. package/dist/Filter.d.ts.map +1 -1
  26. package/dist/Filter.js +15 -0
  27. package/dist/Filter.js.map +1 -1
  28. package/dist/Formatter.js +1 -1
  29. package/dist/Formatter.js.map +1 -1
  30. package/dist/Graph.d.ts.map +1 -1
  31. package/dist/Graph.js +2 -2
  32. package/dist/Graph.js.map +1 -1
  33. package/dist/Latch.d.ts +109 -0
  34. package/dist/Latch.d.ts.map +1 -0
  35. package/dist/Latch.js +72 -0
  36. package/dist/Latch.js.map +1 -0
  37. package/dist/Pipeable.d.ts +17 -0
  38. package/dist/Pipeable.d.ts.map +1 -1
  39. package/dist/Pipeable.js +19 -1
  40. package/dist/Pipeable.js.map +1 -1
  41. package/dist/PlatformError.d.ts +8 -7
  42. package/dist/PlatformError.d.ts.map +1 -1
  43. package/dist/PlatformError.js +2 -2
  44. package/dist/PlatformError.js.map +1 -1
  45. package/dist/Pool.d.ts +5 -3
  46. package/dist/Pool.d.ts.map +1 -1
  47. package/dist/Pool.js +6 -4
  48. package/dist/Pool.js.map +1 -1
  49. package/dist/PubSub.d.ts +3 -2
  50. package/dist/PubSub.d.ts.map +1 -1
  51. package/dist/PubSub.js +3 -2
  52. package/dist/PubSub.js.map +1 -1
  53. package/dist/Request.d.ts +1 -1
  54. package/dist/Request.d.ts.map +1 -1
  55. package/dist/Request.js +2 -1
  56. package/dist/Request.js.map +1 -1
  57. package/dist/RequestResolver.d.ts +0 -20
  58. package/dist/RequestResolver.d.ts.map +1 -1
  59. package/dist/RequestResolver.js +0 -20
  60. package/dist/RequestResolver.js.map +1 -1
  61. package/dist/Schedule.d.ts +2 -2
  62. package/dist/Schedule.d.ts.map +1 -1
  63. package/dist/Schedule.js +30 -16
  64. package/dist/Schedule.js.map +1 -1
  65. package/dist/Schema.d.ts +192 -42
  66. package/dist/Schema.d.ts.map +1 -1
  67. package/dist/Schema.js +385 -71
  68. package/dist/Schema.js.map +1 -1
  69. package/dist/SchemaGetter.d.ts +2 -2
  70. package/dist/SchemaGetter.d.ts.map +1 -1
  71. package/dist/SchemaGetter.js +12 -14
  72. package/dist/SchemaGetter.js.map +1 -1
  73. package/dist/SchemaRepresentation.d.ts +44 -43
  74. package/dist/SchemaRepresentation.d.ts.map +1 -1
  75. package/dist/SchemaRepresentation.js +5 -2
  76. package/dist/SchemaRepresentation.js.map +1 -1
  77. package/dist/SchemaTransformation.d.ts +37 -0
  78. package/dist/SchemaTransformation.d.ts.map +1 -1
  79. package/dist/SchemaTransformation.js +80 -0
  80. package/dist/SchemaTransformation.js.map +1 -1
  81. package/dist/Semaphore.d.ts +211 -0
  82. package/dist/Semaphore.d.ts.map +1 -0
  83. package/dist/{PartitionedSemaphore.js → Semaphore.js} +97 -13
  84. package/dist/Semaphore.js.map +1 -0
  85. package/dist/Stream.d.ts.map +1 -1
  86. package/dist/Stream.js +9 -8
  87. package/dist/Stream.js.map +1 -1
  88. package/dist/Struct.d.ts +16 -0
  89. package/dist/Struct.d.ts.map +1 -1
  90. package/dist/Struct.js +22 -0
  91. package/dist/Struct.js.map +1 -1
  92. package/dist/SubscriptionRef.d.ts +2 -1
  93. package/dist/SubscriptionRef.d.ts.map +1 -1
  94. package/dist/SubscriptionRef.js +2 -1
  95. package/dist/SubscriptionRef.js.map +1 -1
  96. package/dist/SynchronizedRef.d.ts +2 -1
  97. package/dist/SynchronizedRef.d.ts.map +1 -1
  98. package/dist/SynchronizedRef.js +2 -1
  99. package/dist/SynchronizedRef.js.map +1 -1
  100. package/dist/Types.d.ts +14 -6
  101. package/dist/Types.d.ts.map +1 -1
  102. package/dist/index.d.ts +14 -5
  103. package/dist/index.d.ts.map +1 -1
  104. package/dist/index.js +14 -5
  105. package/dist/index.js.map +1 -1
  106. package/dist/internal/core.js +11 -3
  107. package/dist/internal/core.js.map +1 -1
  108. package/dist/internal/effect.js.map +1 -1
  109. package/dist/internal/rcRef.js +2 -1
  110. package/dist/internal/rcRef.js.map +1 -1
  111. package/dist/testing/TestClock.d.ts +3 -2
  112. package/dist/testing/TestClock.d.ts.map +1 -1
  113. package/dist/testing/TestClock.js +5 -3
  114. package/dist/testing/TestClock.js.map +1 -1
  115. package/dist/unstable/ai/AiError.d.ts +39 -39
  116. package/dist/unstable/ai/Chat.d.ts.map +1 -1
  117. package/dist/unstable/ai/Chat.js +2 -1
  118. package/dist/unstable/ai/Chat.js.map +1 -1
  119. package/dist/unstable/ai/McpSchema.d.ts +51 -51
  120. package/dist/unstable/ai/Prompt.d.ts +20 -20
  121. package/dist/unstable/ai/Response.d.ts +25 -25
  122. package/dist/unstable/cli/CliError.d.ts +5 -5
  123. package/dist/unstable/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  124. package/dist/unstable/cluster/ClusterWorkflowEngine.js +2 -1
  125. package/dist/unstable/cluster/ClusterWorkflowEngine.js.map +1 -1
  126. package/dist/unstable/cluster/Entity.d.ts +2 -1
  127. package/dist/unstable/cluster/Entity.d.ts.map +1 -1
  128. package/dist/unstable/cluster/Entity.js.map +1 -1
  129. package/dist/unstable/cluster/Envelope.d.ts +1 -1
  130. package/dist/unstable/cluster/K8sHttpClient.d.ts +1 -1
  131. package/dist/unstable/cluster/Message.d.ts +5 -5
  132. package/dist/unstable/cluster/MessageStorage.d.ts.map +1 -1
  133. package/dist/unstable/cluster/MessageStorage.js +2 -1
  134. package/dist/unstable/cluster/MessageStorage.js.map +1 -1
  135. package/dist/unstable/cluster/Reply.d.ts +3 -3
  136. package/dist/unstable/cluster/Runner.d.ts +1 -1
  137. package/dist/unstable/cluster/Runners.d.ts.map +1 -1
  138. package/dist/unstable/cluster/Runners.js +4 -3
  139. package/dist/unstable/cluster/Runners.js.map +1 -1
  140. package/dist/unstable/cluster/Sharding.d.ts.map +1 -1
  141. package/dist/unstable/cluster/Sharding.js +7 -5
  142. package/dist/unstable/cluster/Sharding.js.map +1 -1
  143. package/dist/unstable/cluster/internal/entityManager.js +4 -3
  144. package/dist/unstable/cluster/internal/entityManager.js.map +1 -1
  145. package/dist/unstable/cluster/internal/entityReaper.js +2 -1
  146. package/dist/unstable/cluster/internal/entityReaper.js.map +1 -1
  147. package/dist/unstable/cluster/internal/resourceRef.js +2 -1
  148. package/dist/unstable/cluster/internal/resourceRef.js.map +1 -1
  149. package/dist/unstable/devtools/DevToolsSchema.d.ts +36 -36
  150. package/dist/unstable/encoding/Sse.d.ts +1 -1
  151. package/dist/unstable/eventlog/EventJournal.d.ts +1 -1
  152. package/dist/unstable/eventlog/EventLog.d.ts.map +1 -1
  153. package/dist/unstable/eventlog/EventLog.js +2 -1
  154. package/dist/unstable/eventlog/EventLog.js.map +1 -1
  155. package/dist/unstable/eventlog/EventLogRemote.d.ts +5 -5
  156. package/dist/unstable/http/Cookies.d.ts +1 -1
  157. package/dist/unstable/http/HttpEffect.d.ts.map +1 -1
  158. package/dist/unstable/http/HttpEffect.js +18 -26
  159. package/dist/unstable/http/HttpEffect.js.map +1 -1
  160. package/dist/unstable/http/Multipart.d.ts +2 -2
  161. package/dist/unstable/http/UrlParams.d.ts +1 -1
  162. package/dist/unstable/httpapi/HttpApiBuilder.js +2 -2
  163. package/dist/unstable/httpapi/HttpApiBuilder.js.map +1 -1
  164. package/dist/unstable/httpapi/HttpApiScalar.d.ts +6 -0
  165. package/dist/unstable/httpapi/HttpApiScalar.d.ts.map +1 -1
  166. package/dist/unstable/httpapi/HttpApiScalar.js.map +1 -1
  167. package/dist/unstable/persistence/KeyValueStore.js +6 -6
  168. package/dist/unstable/persistence/KeyValueStore.js.map +1 -1
  169. package/dist/unstable/persistence/PersistedCache.d.ts +6 -5
  170. package/dist/unstable/persistence/PersistedCache.d.ts.map +1 -1
  171. package/dist/unstable/persistence/PersistedCache.js +2 -1
  172. package/dist/unstable/persistence/PersistedCache.js.map +1 -1
  173. package/dist/unstable/persistence/PersistedQueue.d.ts.map +1 -1
  174. package/dist/unstable/persistence/PersistedQueue.js +6 -5
  175. package/dist/unstable/persistence/PersistedQueue.js.map +1 -1
  176. package/dist/unstable/process/ChildProcessSpawner.d.ts +6 -0
  177. package/dist/unstable/process/ChildProcessSpawner.d.ts.map +1 -1
  178. package/dist/unstable/process/ChildProcessSpawner.js.map +1 -1
  179. package/dist/unstable/reactivity/Atom.d.ts.map +1 -1
  180. package/dist/unstable/reactivity/Atom.js +12 -9
  181. package/dist/unstable/reactivity/Atom.js.map +1 -1
  182. package/dist/unstable/reactivity/Hydration.d.ts +39 -0
  183. package/dist/unstable/reactivity/Hydration.d.ts.map +1 -0
  184. package/dist/unstable/reactivity/Hydration.js +76 -0
  185. package/dist/unstable/reactivity/Hydration.js.map +1 -0
  186. package/dist/unstable/reactivity/index.d.ts +4 -0
  187. package/dist/unstable/reactivity/index.d.ts.map +1 -1
  188. package/dist/unstable/reactivity/index.js +4 -0
  189. package/dist/unstable/reactivity/index.js.map +1 -1
  190. package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
  191. package/dist/unstable/rpc/RpcClient.js +3 -2
  192. package/dist/unstable/rpc/RpcClient.js.map +1 -1
  193. package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
  194. package/dist/unstable/rpc/RpcServer.js +5 -3
  195. package/dist/unstable/rpc/RpcServer.js.map +1 -1
  196. package/dist/unstable/rpc/Utils.d.ts.map +1 -1
  197. package/dist/unstable/rpc/Utils.js +2 -1
  198. package/dist/unstable/rpc/Utils.js.map +1 -1
  199. package/dist/unstable/socket/Socket.d.ts.map +1 -1
  200. package/dist/unstable/socket/Socket.js +3 -2
  201. package/dist/unstable/socket/Socket.js.map +1 -1
  202. package/dist/unstable/sql/Statement.js +0 -1
  203. package/dist/unstable/sql/Statement.js.map +1 -1
  204. package/dist/unstable/workers/Worker.d.ts.map +1 -1
  205. package/dist/unstable/workers/Worker.js +2 -1
  206. package/dist/unstable/workers/Worker.js.map +1 -1
  207. package/dist/unstable/workflow/DurableDeferred.js +2 -2
  208. package/dist/unstable/workflow/DurableDeferred.js.map +1 -1
  209. package/dist/unstable/workflow/Workflow.d.ts +1 -1
  210. package/dist/unstable/workflow/WorkflowEngine.d.ts +2 -1
  211. package/dist/unstable/workflow/WorkflowEngine.d.ts.map +1 -1
  212. package/dist/unstable/workflow/WorkflowEngine.js +2 -1
  213. package/dist/unstable/workflow/WorkflowEngine.js.map +1 -1
  214. package/package.json +1 -2
  215. package/src/Cause.ts +1 -1
  216. package/src/Channel.ts +6 -4
  217. package/src/Data.ts +10 -9
  218. package/src/Effect.ts +0 -246
  219. package/src/Encoding.ts +879 -0
  220. package/src/Equal.ts +2 -2
  221. package/src/FileSystem.ts +7 -8
  222. package/src/Filter.ts +48 -1
  223. package/src/Formatter.ts +1 -1
  224. package/src/Graph.ts +8 -5
  225. package/src/Latch.ts +112 -0
  226. package/src/Pipeable.ts +32 -1
  227. package/src/PlatformError.ts +5 -5
  228. package/src/Pool.ts +9 -7
  229. package/src/PubSub.ts +10 -9
  230. package/src/Request.ts +3 -2
  231. package/src/RequestResolver.ts +0 -20
  232. package/src/Schedule.ts +217 -115
  233. package/src/Schema.ts +567 -105
  234. package/src/SchemaGetter.ts +12 -14
  235. package/src/SchemaRepresentation.ts +5 -2
  236. package/src/SchemaTransformation.ts +104 -0
  237. package/src/Semaphore.ts +356 -0
  238. package/src/Stream.ts +9 -8
  239. package/src/Struct.ts +26 -0
  240. package/src/SubscriptionRef.ts +3 -2
  241. package/src/SynchronizedRef.ts +3 -2
  242. package/src/Types.ts +12 -2
  243. package/src/index.ts +17 -6
  244. package/src/internal/core.ts +10 -2
  245. package/src/internal/effect.ts +3 -2
  246. package/src/internal/rcRef.ts +2 -1
  247. package/src/testing/TestClock.ts +8 -6
  248. package/src/unstable/ai/AiError.ts +1 -1
  249. package/src/unstable/ai/Chat.ts +2 -1
  250. package/src/unstable/ai/Prompt.ts +20 -20
  251. package/src/unstable/ai/Response.ts +22 -22
  252. package/src/unstable/cluster/ClusterWorkflowEngine.ts +3 -2
  253. package/src/unstable/cluster/Entity.ts +2 -1
  254. package/src/unstable/cluster/Envelope.ts +1 -1
  255. package/src/unstable/cluster/MessageStorage.ts +2 -1
  256. package/src/unstable/cluster/Runners.ts +6 -5
  257. package/src/unstable/cluster/Sharding.ts +8 -6
  258. package/src/unstable/cluster/internal/entityManager.ts +6 -5
  259. package/src/unstable/cluster/internal/entityReaper.ts +2 -1
  260. package/src/unstable/cluster/internal/resourceRef.ts +2 -1
  261. package/src/unstable/eventlog/EventLog.ts +2 -1
  262. package/src/unstable/http/HttpEffect.ts +17 -25
  263. package/src/unstable/http/Multipart.ts +2 -2
  264. package/src/unstable/http/UrlParams.ts +1 -1
  265. package/src/unstable/httpapi/HttpApiBuilder.ts +2 -2
  266. package/src/unstable/httpapi/HttpApiScalar.ts +6 -0
  267. package/src/unstable/persistence/KeyValueStore.ts +6 -6
  268. package/src/unstable/persistence/PersistedCache.ts +20 -9
  269. package/src/unstable/persistence/PersistedQueue.ts +7 -6
  270. package/src/unstable/process/ChildProcessSpawner.ts +6 -0
  271. package/src/unstable/reactivity/Atom.ts +7 -5
  272. package/src/unstable/reactivity/Hydration.ts +112 -0
  273. package/src/unstable/reactivity/index.ts +5 -0
  274. package/src/unstable/rpc/RpcClient.ts +4 -3
  275. package/src/unstable/rpc/RpcServer.ts +6 -4
  276. package/src/unstable/rpc/Utils.ts +2 -1
  277. package/src/unstable/socket/Socket.ts +3 -2
  278. package/src/unstable/sql/Statement.ts +0 -1
  279. package/src/unstable/workers/Worker.ts +2 -1
  280. package/src/unstable/workflow/DurableDeferred.ts +2 -2
  281. package/src/unstable/workflow/WorkflowEngine.ts +3 -2
  282. package/dist/PartitionedSemaphore.d.ts +0 -52
  283. package/dist/PartitionedSemaphore.d.ts.map +0 -1
  284. package/dist/PartitionedSemaphore.js.map +0 -1
  285. package/dist/encoding/Base64.d.ts +0 -67
  286. package/dist/encoding/Base64.d.ts.map +0 -1
  287. package/dist/encoding/Base64.js +0 -146
  288. package/dist/encoding/Base64.js.map +0 -1
  289. package/dist/encoding/Base64Url.d.ts +0 -60
  290. package/dist/encoding/Base64Url.d.ts.map +0 -1
  291. package/dist/encoding/Base64Url.js +0 -89
  292. package/dist/encoding/Base64Url.js.map +0 -1
  293. package/dist/encoding/EncodingError.d.ts +0 -31
  294. package/dist/encoding/EncodingError.d.ts.map +0 -1
  295. package/dist/encoding/EncodingError.js +0 -22
  296. package/dist/encoding/EncodingError.js.map +0 -1
  297. package/dist/encoding/Hex.d.ts +0 -61
  298. package/dist/encoding/Hex.d.ts.map +0 -1
  299. package/dist/encoding/Hex.js +0 -115
  300. package/dist/encoding/Hex.js.map +0 -1
  301. package/dist/encoding/index.d.ts +0 -26
  302. package/dist/encoding/index.d.ts.map +0 -1
  303. package/dist/encoding/index.js +0 -27
  304. package/dist/encoding/index.js.map +0 -1
  305. package/src/PartitionedSemaphore.ts +0 -182
  306. package/src/encoding/Base64.ts +0 -366
  307. package/src/encoding/Base64Url.ts +0 -104
  308. package/src/encoding/EncodingError.ts +0 -35
  309. package/src/encoding/Hex.ts +0 -390
  310. package/src/encoding/index.ts +0 -31
@@ -1,182 +0,0 @@
1
- /**
2
- * @since 3.19.4
3
- * @experimental
4
- */
5
- import * as Effect from "./Effect.ts"
6
- import * as MutableHashMap from "./MutableHashMap.ts"
7
- import * as Option from "./Option.ts"
8
-
9
- /**
10
- * @since 3.19.4
11
- * @category models
12
- * @experimental
13
- */
14
- export const TypeId: TypeId = "~effect/PartitionedSemaphore"
15
-
16
- /**
17
- * @since 3.19.4
18
- * @category models
19
- * @experimental
20
- */
21
- export type TypeId = "~effect/PartitionedSemaphore"
22
-
23
- /**
24
- * A `PartitionedSemaphore` controls access to a shared permit pool while
25
- * tracking waiters by partition key.
26
- *
27
- * Waiting permits are distributed across partitions in round-robin order.
28
- *
29
- * @since 3.19.4
30
- * @category models
31
- * @experimental
32
- */
33
- export interface PartitionedSemaphore<in K> {
34
- readonly [TypeId]: TypeId
35
- readonly withPermits: (
36
- key: K,
37
- permits: number
38
- ) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>
39
- }
40
-
41
- /**
42
- * Creates a `PartitionedSemaphore` unsafely.
43
- *
44
- * @since 3.19.4
45
- * @category constructors
46
- * @experimental
47
- */
48
- export const makeUnsafe = <K = unknown>(options: {
49
- readonly permits: number
50
- }): PartitionedSemaphore<K> => {
51
- const maxPermits = Math.max(0, options.permits)
52
-
53
- if (!Number.isFinite(maxPermits)) {
54
- return {
55
- [TypeId]: TypeId,
56
- withPermits: () => (effect) => effect
57
- }
58
- }
59
-
60
- let totalPermits = maxPermits
61
- let waitingPermits = 0
62
-
63
- type Waiter = {
64
- permits: number
65
- readonly resume: () => void
66
- }
67
- const partitions = MutableHashMap.empty<K, Set<Waiter>>()
68
-
69
- const take = (key: K, permits: number) =>
70
- Effect.callback<void>((resume) => {
71
- if (maxPermits < permits) {
72
- resume(Effect.never)
73
- return
74
- }
75
-
76
- if (totalPermits >= permits) {
77
- totalPermits -= permits
78
- resume(Effect.void)
79
- return
80
- }
81
-
82
- const needed = permits - totalPermits
83
- const taken = permits - needed
84
- if (totalPermits > 0) {
85
- totalPermits = 0
86
- }
87
- waitingPermits += needed
88
-
89
- const waiters = Option.getOrElse(
90
- MutableHashMap.get(partitions, key),
91
- () => {
92
- const set = new Set<Waiter>()
93
- MutableHashMap.set(partitions, key, set)
94
- return set
95
- }
96
- )
97
-
98
- const entry: Waiter = {
99
- permits: needed,
100
- resume: () => {
101
- cleanup()
102
- resume(Effect.void)
103
- }
104
- }
105
-
106
- const cleanup = () => {
107
- waiters.delete(entry)
108
- if (waiters.size === 0) {
109
- MutableHashMap.remove(partitions, key)
110
- }
111
- }
112
-
113
- waiters.add(entry)
114
-
115
- return Effect.sync(() => {
116
- cleanup()
117
- waitingPermits -= entry.permits
118
- if (taken > 0) {
119
- releaseUnsafe(taken)
120
- }
121
- })
122
- })
123
-
124
- let iterator = partitions[Symbol.iterator]()
125
-
126
- const releaseUnsafe = (permits: number): void => {
127
- while (permits > 0) {
128
- if (waitingPermits === 0) {
129
- totalPermits += permits
130
- return
131
- }
132
-
133
- let state = iterator.next()
134
- if (state.done) {
135
- iterator = partitions[Symbol.iterator]()
136
- state = iterator.next()
137
- if (state.done) {
138
- return
139
- }
140
- }
141
-
142
- const waiter = state.value[1].values().next().value
143
- if (waiter === undefined) {
144
- continue
145
- }
146
-
147
- waiter.permits -= 1
148
- waitingPermits -= 1
149
-
150
- if (waiter.permits === 0) {
151
- waiter.resume()
152
- }
153
-
154
- permits -= 1
155
- }
156
- }
157
-
158
- return {
159
- [TypeId]: TypeId,
160
- withPermits: (key, permits) => {
161
- const takePermits = take(key, permits)
162
- return (effect) =>
163
- Effect.uninterruptibleMask((restore) =>
164
- Effect.flatMap(
165
- restore(takePermits),
166
- () => Effect.ensuring(restore(effect), Effect.sync(() => releaseUnsafe(permits)))
167
- )
168
- )
169
- }
170
- }
171
- }
172
-
173
- /**
174
- * Creates a `PartitionedSemaphore`.
175
- *
176
- * @since 3.19.4
177
- * @category constructors
178
- * @experimental
179
- */
180
- export const make = <K = unknown>(options: {
181
- readonly permits: number
182
- }): Effect.Effect<PartitionedSemaphore<K>> => Effect.sync(() => makeUnsafe<K>(options))
@@ -1,366 +0,0 @@
1
- /**
2
- * This module provides encoding & decoding functionality for:
3
- *
4
- * - base64 (RFC4648)
5
- * - base64 (URL)
6
- * - hex
7
- *
8
- * @since 2.0.0
9
- */
10
- import * as Result from "../Result.ts"
11
- import { EncodingError } from "./EncodingError.ts"
12
-
13
- /**
14
- * Encodes the given value into a base64 (RFC4648) `string`.
15
- *
16
- * @example
17
- * ```ts
18
- * import { Base64 } from "effect/encoding"
19
- *
20
- * // Encode a string
21
- * console.log(Base64.encode("hello")) // "aGVsbG8="
22
- *
23
- * // Encode binary data
24
- * const bytes = new Uint8Array([72, 101, 108, 108, 111])
25
- * console.log(Base64.encode(bytes)) // "SGVsbG8="
26
- * ```
27
- *
28
- * @category encoding
29
- * @since 2.0.0
30
- */
31
- export const encode: (input: Uint8Array | string) => string = (input) =>
32
- typeof input === "string" ? encodeUint8Array(encoder.encode(input)) : encodeUint8Array(input)
33
-
34
- const encodeUint8Array = (bytes: Uint8Array) => {
35
- const length = bytes.length
36
-
37
- let result = ""
38
- let i: number
39
-
40
- for (i = 2; i < length; i += 3) {
41
- result += base64abc[bytes[i - 2] >> 2]
42
- result += base64abc[((bytes[i - 2] & 0x03) << 4) | (bytes[i - 1] >> 4)]
43
- result += base64abc[((bytes[i - 1] & 0x0f) << 2) | (bytes[i] >> 6)]
44
- result += base64abc[bytes[i] & 0x3f]
45
- }
46
-
47
- if (i === length + 1) {
48
- // 1 octet yet to write
49
- result += base64abc[bytes[i - 2] >> 2]
50
- result += base64abc[(bytes[i - 2] & 0x03) << 4]
51
- result += "=="
52
- }
53
-
54
- if (i === length) {
55
- // 2 octets yet to write
56
- result += base64abc[bytes[i - 2] >> 2]
57
- result += base64abc[((bytes[i - 2] & 0x03) << 4) | (bytes[i - 1] >> 4)]
58
- result += base64abc[(bytes[i - 1] & 0x0f) << 2]
59
- result += "="
60
- }
61
-
62
- return result
63
- }
64
-
65
- /**
66
- * Decodes a base64 (RFC4648) encoded `string` into a `Uint8Array`.
67
- *
68
- * @example
69
- * ```ts
70
- * import { Result } from "effect"
71
- * import { Base64 } from "effect/encoding"
72
- *
73
- * const result = Base64.decode("SGVsbG8=")
74
- * if (Result.isSuccess(result)) {
75
- * console.log(Array.from(result.success)) // [72, 101, 108, 108, 111]
76
- * }
77
- * ```
78
- *
79
- * @category decoding
80
- * @since 2.0.0
81
- */
82
- export const decode = (str: string): Result.Result<Uint8Array, EncodingError> => {
83
- const stripped = stripCrlf(str)
84
- const length = stripped.length
85
- if (length % 4 !== 0) {
86
- return Result.fail(
87
- new EncodingError({
88
- kind: "Decode",
89
- module: "Base64",
90
- input: stripped,
91
- message: `Length must be a multiple of 4, but is ${length}`
92
- })
93
- )
94
- }
95
-
96
- const index = stripped.indexOf("=")
97
- if (index !== -1 && ((index < length - 2) || (index === length - 2 && stripped[length - 1] !== "="))) {
98
- return Result.fail(
99
- new EncodingError({
100
- kind: "Decode",
101
- module: "Base64",
102
- input: stripped,
103
- message: `Found a '=' character, but it is not at the end`
104
- })
105
- )
106
- }
107
-
108
- try {
109
- const missingOctets = stripped.endsWith("==") ? 2 : stripped.endsWith("=") ? 1 : 0
110
- const result = new Uint8Array(3 * (length / 4) - missingOctets)
111
- for (let i = 0, j = 0; i < length; i += 4, j += 3) {
112
- const buffer = getBase64Code(stripped.charCodeAt(i)) << 18 |
113
- getBase64Code(stripped.charCodeAt(i + 1)) << 12 |
114
- getBase64Code(stripped.charCodeAt(i + 2)) << 6 |
115
- getBase64Code(stripped.charCodeAt(i + 3))
116
-
117
- result[j] = buffer >> 16
118
- result[j + 1] = (buffer >> 8) & 0xff
119
- result[j + 2] = buffer & 0xff
120
- }
121
-
122
- return Result.succeed(result)
123
- } catch (e) {
124
- return Result.fail(
125
- new EncodingError({
126
- kind: "Decode",
127
- module: "Base64",
128
- input: stripped,
129
- message: e instanceof Error ? e.message : "Invalid input"
130
- })
131
- )
132
- }
133
- }
134
-
135
- /**
136
- * Decodes a base64 (RFC4648) encoded `string` into a UTF-8 `string`.
137
- *
138
- * @example
139
- * ```ts
140
- * import { Result } from "effect"
141
- * import { Base64 } from "effect/encoding"
142
- *
143
- * const result = Base64.decodeString("aGVsbG8=")
144
- * if (Result.isSuccess(result)) {
145
- * console.log(result.success) // "hello"
146
- * }
147
- * ```
148
- *
149
- * @category decoding
150
- * @since 2.0.0
151
- */
152
- export const decodeString = (str: string) => Result.map(decode(str), (_) => decoder.decode(_))
153
-
154
- // Internal utils
155
-
156
- const encoder = new TextEncoder()
157
-
158
- const decoder = new TextDecoder()
159
-
160
- const stripCrlf = (str: string) => str.replace(/[\n\r]/g, "")
161
-
162
- function getBase64Code(charCode: number) {
163
- if (charCode >= base64codes.length) {
164
- throw new TypeError(`Invalid character ${String.fromCharCode(charCode)}`)
165
- }
166
-
167
- const code = base64codes[charCode]
168
- if (code === 255) {
169
- throw new TypeError(`Invalid character ${String.fromCharCode(charCode)}`)
170
- }
171
-
172
- return code
173
- }
174
-
175
- const base64abc = [
176
- "A",
177
- "B",
178
- "C",
179
- "D",
180
- "E",
181
- "F",
182
- "G",
183
- "H",
184
- "I",
185
- "J",
186
- "K",
187
- "L",
188
- "M",
189
- "N",
190
- "O",
191
- "P",
192
- "Q",
193
- "R",
194
- "S",
195
- "T",
196
- "U",
197
- "V",
198
- "W",
199
- "X",
200
- "Y",
201
- "Z",
202
- "a",
203
- "b",
204
- "c",
205
- "d",
206
- "e",
207
- "f",
208
- "g",
209
- "h",
210
- "i",
211
- "j",
212
- "k",
213
- "l",
214
- "m",
215
- "n",
216
- "o",
217
- "p",
218
- "q",
219
- "r",
220
- "s",
221
- "t",
222
- "u",
223
- "v",
224
- "w",
225
- "x",
226
- "y",
227
- "z",
228
- "0",
229
- "1",
230
- "2",
231
- "3",
232
- "4",
233
- "5",
234
- "6",
235
- "7",
236
- "8",
237
- "9",
238
- "+",
239
- "/"
240
- ]
241
-
242
- const base64codes = [
243
- 255,
244
- 255,
245
- 255,
246
- 255,
247
- 255,
248
- 255,
249
- 255,
250
- 255,
251
- 255,
252
- 255,
253
- 255,
254
- 255,
255
- 255,
256
- 255,
257
- 255,
258
- 255,
259
- 255,
260
- 255,
261
- 255,
262
- 255,
263
- 255,
264
- 255,
265
- 255,
266
- 255,
267
- 255,
268
- 255,
269
- 255,
270
- 255,
271
- 255,
272
- 255,
273
- 255,
274
- 255,
275
- 255,
276
- 255,
277
- 255,
278
- 255,
279
- 255,
280
- 255,
281
- 255,
282
- 255,
283
- 255,
284
- 255,
285
- 255,
286
- 62,
287
- 255,
288
- 255,
289
- 255,
290
- 63,
291
- 52,
292
- 53,
293
- 54,
294
- 55,
295
- 56,
296
- 57,
297
- 58,
298
- 59,
299
- 60,
300
- 61,
301
- 255,
302
- 255,
303
- 255,
304
- 0,
305
- 255,
306
- 255,
307
- 255,
308
- 0,
309
- 1,
310
- 2,
311
- 3,
312
- 4,
313
- 5,
314
- 6,
315
- 7,
316
- 8,
317
- 9,
318
- 10,
319
- 11,
320
- 12,
321
- 13,
322
- 14,
323
- 15,
324
- 16,
325
- 17,
326
- 18,
327
- 19,
328
- 20,
329
- 21,
330
- 22,
331
- 23,
332
- 24,
333
- 25,
334
- 255,
335
- 255,
336
- 255,
337
- 255,
338
- 255,
339
- 255,
340
- 26,
341
- 27,
342
- 28,
343
- 29,
344
- 30,
345
- 31,
346
- 32,
347
- 33,
348
- 34,
349
- 35,
350
- 36,
351
- 37,
352
- 38,
353
- 39,
354
- 40,
355
- 41,
356
- 42,
357
- 43,
358
- 44,
359
- 45,
360
- 46,
361
- 47,
362
- 48,
363
- 49,
364
- 50,
365
- 51
366
- ]
@@ -1,104 +0,0 @@
1
- /**
2
- * @since 2.0.0
3
- */
4
- import * as Result from "../Result.ts"
5
- import * as Base64 from "./Base64.ts"
6
- import { EncodingError } from "./EncodingError.ts"
7
-
8
- /**
9
- * Encodes the given value into a base64 (URL) `string`.
10
- *
11
- * @example
12
- * ```ts
13
- * import { Base64Url } from "effect/encoding"
14
- *
15
- * // URL-safe base64 encoding (uses - and _ instead of + and /)
16
- * console.log(Base64Url.encode("hello?")) // "aGVsbG8_"
17
- *
18
- * const bytes = new Uint8Array([72, 101, 108, 108, 111, 63])
19
- * console.log(Base64Url.encode(bytes)) // "SGVsbG8_"
20
- * ```
21
- *
22
- * @category encoding
23
- * @since 2.0.0
24
- */
25
- export const encode: (input: Uint8Array | string) => string = (input) =>
26
- typeof input === "string" ? encodeUint8Array(encoder.encode(input)) : encodeUint8Array(input)
27
-
28
- const encodeUint8Array = (data: Uint8Array) =>
29
- Base64.encode(data).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_")
30
-
31
- /**
32
- * Decodes a base64 (URL) encoded `string` into a `Uint8Array`.
33
- *
34
- * @example
35
- * ```ts
36
- * import { Result } from "effect"
37
- * import { Base64Url } from "effect/encoding"
38
- *
39
- * const result = Base64Url.decode("SGVsbG8_")
40
- * if (Result.isSuccess(result)) {
41
- * console.log(Array.from(result.success)) // [72, 101, 108, 108, 111, 63]
42
- * }
43
- * ```
44
- *
45
- * @category decoding
46
- * @since 2.0.0
47
- */
48
- export const decode = (str: string): Result.Result<Uint8Array, EncodingError> => {
49
- const stripped = stripCrlf(str)
50
- const length = stripped.length
51
- if (length % 4 === 1) {
52
- return Result.fail(
53
- new EncodingError({
54
- module: "Base64Url",
55
- kind: "Decode",
56
- input: stripped,
57
- message: `Length should be a multiple of 4, but is ${length}`
58
- })
59
- )
60
- }
61
-
62
- if (!/^[-_A-Z0-9]*?={0,2}$/i.test(stripped)) {
63
- return Result.fail(
64
- new EncodingError({
65
- module: "Base64Url",
66
- kind: "Decode",
67
- input: stripped,
68
- message: "Invalid input"
69
- })
70
- )
71
- }
72
-
73
- // Some variants allow or require omitting the padding '=' signs
74
- let sanitized = length % 4 === 2 ? `${stripped}==` : length % 4 === 3 ? `${stripped}=` : stripped
75
- sanitized = sanitized.replace(/-/g, "+").replace(/_/g, "/")
76
-
77
- return Base64.decode(sanitized)
78
- }
79
-
80
- /**
81
- * Decodes a base64 (URL) encoded `string` into a UTF-8 `string`.
82
- *
83
- * @example
84
- * ```ts
85
- * import { Result } from "effect"
86
- * import { Base64Url } from "effect/encoding"
87
- *
88
- * const result = Base64Url.decodeString("aGVsbG8_")
89
- * if (Result.isSuccess(result)) {
90
- * console.log(result.success) // "hello?"
91
- * }
92
- * ```
93
- *
94
- * @category decoding
95
- * @since 2.0.0
96
- */
97
- export const decodeString = (str: string) => Result.map(decode(str), (_) => decoder.decode(_))
98
-
99
- // Internal
100
-
101
- const encoder = new TextEncoder()
102
- const decoder = new TextDecoder()
103
-
104
- const stripCrlf = (str: string) => str.replace(/[\n\r]/g, "")
@@ -1,35 +0,0 @@
1
- /**
2
- * @since 4.0.0
3
- */
4
- import * as Data from "../Data.ts"
5
- import { hasProperty } from "../Predicate.ts"
6
-
7
- const EncodingErrorTypeId = "~effect/encoding/EncodingError" as const
8
-
9
- /**
10
- * @category symbols
11
- * @since 2.0.0
12
- */
13
- export type EncodingErrorTypeId = typeof EncodingErrorTypeId
14
-
15
- /**
16
- * @category constructors
17
- * @since 4.0.0
18
- */
19
- export class EncodingError extends Data.TaggedError("EncodingError")<{
20
- kind: "Decode" | "Encode"
21
- module: string
22
- input: unknown
23
- message: string
24
- }> {
25
- /**
26
- * @since 4.0.0
27
- */
28
- readonly [EncodingErrorTypeId]: EncodingErrorTypeId = EncodingErrorTypeId
29
- }
30
-
31
- /**
32
- * @category guards
33
- * @since 2.0.0
34
- */
35
- export const isEncodingError = (u: unknown): u is EncodingError => hasProperty(u, EncodingErrorTypeId)