@knpkv/atlassian-common 0.2.0 → 0.3.0

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 (57) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/Brand.d.ts +15 -15
  3. package/dist/Brand.d.ts.map +1 -1
  4. package/dist/Brand.js +5 -5
  5. package/dist/Brand.js.map +1 -1
  6. package/dist/Hash.d.ts +12 -14
  7. package/dist/Hash.d.ts.map +1 -1
  8. package/dist/Hash.js +18 -24
  9. package/dist/Hash.js.map +1 -1
  10. package/dist/ast/BlockNode.d.ts +120 -177
  11. package/dist/ast/BlockNode.d.ts.map +1 -1
  12. package/dist/ast/BlockNode.js +28 -8
  13. package/dist/ast/BlockNode.js.map +1 -1
  14. package/dist/ast/Document.d.ts +114 -156
  15. package/dist/ast/Document.d.ts.map +1 -1
  16. package/dist/ast/Document.js +1 -1
  17. package/dist/ast/Document.js.map +1 -1
  18. package/dist/ast/InlineNode.d.ts +59 -247
  19. package/dist/ast/InlineNode.d.ts.map +1 -1
  20. package/dist/ast/InlineNode.js +28 -3
  21. package/dist/ast/InlineNode.js.map +1 -1
  22. package/dist/ast/MacroNode.d.ts +62 -102
  23. package/dist/ast/MacroNode.d.ts.map +1 -1
  24. package/dist/ast/MacroNode.js +12 -5
  25. package/dist/ast/MacroNode.js.map +1 -1
  26. package/dist/auth/OAuthOperations.d.ts +1 -1
  27. package/dist/auth/OAuthOperations.d.ts.map +1 -1
  28. package/dist/auth/OAuthOperations.js +5 -6
  29. package/dist/auth/OAuthOperations.js.map +1 -1
  30. package/dist/auth/OAuthResponseSchemas.d.ts +13 -13
  31. package/dist/config/ConfigPaths.d.ts +6 -26
  32. package/dist/config/ConfigPaths.d.ts.map +1 -1
  33. package/dist/config/ConfigPaths.js +23 -3
  34. package/dist/config/ConfigPaths.js.map +1 -1
  35. package/dist/config/OAuthSchemas.d.ts +24 -24
  36. package/dist/config/TokenStorage.d.ts +5 -24
  37. package/dist/config/TokenStorage.d.ts.map +1 -1
  38. package/dist/config/TokenStorage.js +35 -22
  39. package/dist/config/TokenStorage.js.map +1 -1
  40. package/dist/index.d.ts +1 -1
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +1 -1
  43. package/dist/index.js.map +1 -1
  44. package/package.json +7 -9
  45. package/src/Brand.ts +5 -17
  46. package/src/Hash.ts +27 -27
  47. package/src/ast/BlockNode.ts +13 -13
  48. package/src/ast/Document.ts +1 -1
  49. package/src/ast/InlineNode.ts +5 -5
  50. package/src/ast/MacroNode.ts +7 -6
  51. package/src/auth/OAuthOperations.ts +5 -6
  52. package/src/config/ConfigPaths.ts +7 -7
  53. package/src/config/TokenStorage.ts +23 -27
  54. package/src/index.ts +1 -1
  55. package/test/Hash.test.ts +52 -0
  56. package/test/OAuthOperations.test.ts +2 -3
  57. package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @knpkv/atlassian-common
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#71](https://github.com/knpkv/npm/pull/71) [`e3c3805`](https://github.com/knpkv/npm/commit/e3c3805ee527a6edb69ed91977c95c586b563ff9) Thanks [@konopkov](https://github.com/konopkov)! - Migrate the package workspace to Effect v4 beta.
8
+
9
+ This updates runtime and peer dependencies to the Effect v4 beta module layout,
10
+ adopts Effect platform/runtime services for Node process, HTTP, filesystem, and
11
+ clock access, and refreshes package export metadata to point published type
12
+ entries at emitted `dist/*.d.ts` declarations.
13
+
14
+ CodeCommit packages now use Effect v4-compatible AWS and cache layers, including
15
+ typed `distilled-aws` context services, shared cached-comment decoding, and
16
+ schema-derived config defaults. Jira and Confluence OAuth callback servers bind
17
+ the expected local callback port range again under the Effect v4 Node HTTP
18
+ server layer.
19
+
20
+ The retired Claude AI packages have been removed from the workspace.
21
+
3
22
  ## 0.2.0
4
23
 
5
24
  ### Minor Changes
package/dist/Brand.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * **Mental model**
5
5
  *
6
6
  * - **Brand = runtime validation + compile-time narrowing**: Each brand combines
7
- * an Effect `Brand.refined` (throws on invalid values) with an Effect `Schema`
7
+ * an Effect `Brand.make` (throws on invalid values) with an Effect `Schema`
8
8
  * (composable validation). The `Type` property exposes the branded type for use
9
9
  * in type annotations.
10
10
  * - **Pattern-guarded strings**: `SpaceKey`, `IssueKey`, `ProjectKey` are regex-branded;
@@ -41,8 +41,8 @@ import * as Schema from "effect/Schema";
41
41
  *
42
42
  * @category Brand
43
43
  */
44
- export declare const makeBrandedString: <B extends string>(name: B, pattern: RegExp) => Brand.Brand.Constructor<string & Brand.Brand<B>> & {
45
- schema: Schema.brand<Schema.filter<typeof Schema.String>, B>;
44
+ export declare const makeBrandedString: <B extends string>(name: B, pattern: RegExp) => Brand.Constructor<string & Brand.Brand<B>> & {
45
+ schema: Schema.brand<Schema.String, B>;
46
46
  Type: string & Brand.Brand<B>;
47
47
  };
48
48
  /**
@@ -61,8 +61,8 @@ export declare const makeBrandedString: <B extends string>(name: B, pattern: Reg
61
61
  *
62
62
  * @category Brand
63
63
  */
64
- export declare const makeBrandedNonEmptyString: <B extends string>(name: B) => Brand.Brand.Constructor<string & Brand.Brand<B>> & {
65
- schema: Schema.brand<Schema.filter<typeof Schema.String>, B>;
64
+ export declare const makeBrandedNonEmptyString: <B extends string>(name: B) => Brand.Constructor<string & Brand.Brand<B>> & {
65
+ schema: Schema.brand<Schema.NonEmptyString, B>;
66
66
  Type: string & Brand.Brand<B>;
67
67
  };
68
68
  /**
@@ -70,8 +70,8 @@ export declare const makeBrandedNonEmptyString: <B extends string>(name: B) => B
70
70
  *
71
71
  * @category Brand
72
72
  */
73
- export declare const PageId: Brand.Brand.Constructor<string & Brand.Brand<"PageId">> & {
74
- schema: Schema.brand<Schema.filter<typeof Schema.String>, "PageId">;
73
+ export declare const PageId: Brand.Constructor<string & Brand.Brand<"PageId">> & {
74
+ schema: Schema.brand<Schema.NonEmptyString, "PageId">;
75
75
  Type: string & Brand.Brand<"PageId">;
76
76
  };
77
77
  export type PageId = typeof PageId.Type;
@@ -80,8 +80,8 @@ export type PageId = typeof PageId.Type;
80
80
  *
81
81
  * @category Brand
82
82
  */
83
- export declare const SpaceKey: Brand.Brand.Constructor<string & Brand.Brand<"SpaceKey">> & {
84
- schema: Schema.brand<Schema.filter<typeof Schema.String>, "SpaceKey">;
83
+ export declare const SpaceKey: Brand.Constructor<string & Brand.Brand<"SpaceKey">> & {
84
+ schema: Schema.brand<Schema.String, "SpaceKey">;
85
85
  Type: string & Brand.Brand<"SpaceKey">;
86
86
  };
87
87
  export type SpaceKey = typeof SpaceKey.Type;
@@ -90,8 +90,8 @@ export type SpaceKey = typeof SpaceKey.Type;
90
90
  *
91
91
  * @category Brand
92
92
  */
93
- export declare const IssueKey: Brand.Brand.Constructor<string & Brand.Brand<"IssueKey">> & {
94
- schema: Schema.brand<Schema.filter<typeof Schema.String>, "IssueKey">;
93
+ export declare const IssueKey: Brand.Constructor<string & Brand.Brand<"IssueKey">> & {
94
+ schema: Schema.brand<Schema.String, "IssueKey">;
95
95
  Type: string & Brand.Brand<"IssueKey">;
96
96
  };
97
97
  export type IssueKey = typeof IssueKey.Type;
@@ -100,8 +100,8 @@ export type IssueKey = typeof IssueKey.Type;
100
100
  *
101
101
  * @category Brand
102
102
  */
103
- export declare const ProjectKey: Brand.Brand.Constructor<string & Brand.Brand<"ProjectKey">> & {
104
- schema: Schema.brand<Schema.filter<typeof Schema.String>, "ProjectKey">;
103
+ export declare const ProjectKey: Brand.Constructor<string & Brand.Brand<"ProjectKey">> & {
104
+ schema: Schema.brand<Schema.String, "ProjectKey">;
105
105
  Type: string & Brand.Brand<"ProjectKey">;
106
106
  };
107
107
  export type ProjectKey = typeof ProjectKey.Type;
@@ -110,8 +110,8 @@ export type ProjectKey = typeof ProjectKey.Type;
110
110
  *
111
111
  * @category Brand
112
112
  */
113
- export declare const ContentHash: Brand.Brand.Constructor<string & Brand.Brand<"ContentHash">> & {
114
- schema: Schema.brand<Schema.filter<typeof Schema.String>, "ContentHash">;
113
+ export declare const ContentHash: Brand.Constructor<string & Brand.Brand<"ContentHash">> & {
114
+ schema: Schema.brand<Schema.String, "ContentHash">;
115
115
  Type: string & Brand.Brand<"ContentHash">;
116
116
  };
117
117
  export type ContentHash = typeof ContentHash.Type;
@@ -1 +1 @@
1
- {"version":3,"file":"Brand.d.ts","sourceRoot":"","sources":["../src/Brand.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,MAAM,EAChD,MAAM,CAAC,EACP,SAAS,MAAM;;;CAkBhB,CAAA;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,yBAAyB,GAAI,CAAC,SAAS,MAAM,EAAE,MAAM,CAAC;;;CAiBlE,CAAA;AAID;;;;GAIG;AACH,eAAO,MAAM,MAAM;;;CAAsC,CAAA;AACzD,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC,IAAI,CAAA;AAEvC;;;;GAIG;AACH,eAAO,MAAM,QAAQ;;;CAAoD,CAAA;AACzE,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,IAAI,CAAA;AAE3C;;;;GAIG;AACH,eAAO,MAAM,QAAQ;;;CAAwD,CAAA;AAC7E,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,IAAI,CAAA;AAE3C;;;;GAIG;AACH,eAAO,MAAM,UAAU;;;CAAsD,CAAA;AAC7E,MAAM,MAAM,UAAU,GAAG,OAAO,UAAU,CAAC,IAAI,CAAA;AAE/C;;;;GAIG;AACH,eAAO,MAAM,WAAW;;;CAAqD,CAAA;AAC7E,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC,IAAI,CAAA"}
1
+ {"version":3,"file":"Brand.d.ts","sourceRoot":"","sources":["../src/Brand.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,MAAM,EAChD,MAAM,CAAC,EACP,SAAS,MAAM;;;CAYhB,CAAA;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,yBAAyB,GAAI,CAAC,SAAS,MAAM,EAAE,MAAM,CAAC;;;CAWlE,CAAA;AAID;;;;GAIG;AACH,eAAO,MAAM,MAAM;;;CAAsC,CAAA;AACzD,MAAM,MAAM,MAAM,GAAG,OAAO,MAAM,CAAC,IAAI,CAAA;AAEvC;;;;GAIG;AACH,eAAO,MAAM,QAAQ;;;CAAoD,CAAA;AACzE,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,IAAI,CAAA;AAE3C;;;;GAIG;AACH,eAAO,MAAM,QAAQ;;;CAAwD,CAAA;AAC7E,MAAM,MAAM,QAAQ,GAAG,OAAO,QAAQ,CAAC,IAAI,CAAA;AAE3C;;;;GAIG;AACH,eAAO,MAAM,UAAU;;;CAAsD,CAAA;AAC7E,MAAM,MAAM,UAAU,GAAG,OAAO,UAAU,CAAC,IAAI,CAAA;AAE/C;;;;GAIG;AACH,eAAO,MAAM,WAAW;;;CAAqD,CAAA;AAC7E,MAAM,MAAM,WAAW,GAAG,OAAO,WAAW,CAAC,IAAI,CAAA"}
package/dist/Brand.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * **Mental model**
5
5
  *
6
6
  * - **Brand = runtime validation + compile-time narrowing**: Each brand combines
7
- * an Effect `Brand.refined` (throws on invalid values) with an Effect `Schema`
7
+ * an Effect `Brand.make` (throws on invalid values) with an Effect `Schema`
8
8
  * (composable validation). The `Type` property exposes the branded type for use
9
9
  * in type annotations.
10
10
  * - **Pattern-guarded strings**: `SpaceKey`, `IssueKey`, `ProjectKey` are regex-branded;
@@ -42,8 +42,8 @@ import * as Schema from "effect/Schema";
42
42
  * @category Brand
43
43
  */
44
44
  export const makeBrandedString = (name, pattern) => {
45
- const brand = Brand.refined((s) => pattern.test(s), (s) => Brand.error(`Invalid ${name}: ${s} does not match ${pattern}`));
46
- const schema = Schema.String.pipe(Schema.pattern(pattern), Schema.brand(name));
45
+ const brand = Brand.make((s) => pattern.test(s) || `Invalid ${name}: ${s} does not match ${pattern}`);
46
+ const schema = Schema.String.check(Schema.isPattern(pattern)).pipe(Schema.brand(name));
47
47
  return Object.assign(brand, {
48
48
  schema,
49
49
  Type: undefined
@@ -66,8 +66,8 @@ export const makeBrandedString = (name, pattern) => {
66
66
  * @category Brand
67
67
  */
68
68
  export const makeBrandedNonEmptyString = (name) => {
69
- const brand = Brand.refined((s) => s.length > 0, (_s) => Brand.error(`${name} cannot be empty`));
70
- const schema = Schema.String.pipe(Schema.nonEmptyString(), Schema.brand(name));
69
+ const brand = Brand.make((s) => s.length > 0 || `${name} cannot be empty`);
70
+ const schema = Schema.NonEmptyString.pipe(Schema.brand(name));
71
71
  return Object.assign(brand, {
72
72
  schema,
73
73
  Type: undefined
package/dist/Brand.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Brand.js","sourceRoot":"","sources":["../src/Brand.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,IAAO,EACP,OAAe,EACf,EAAE;IAGF,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CACzB,CAAC,CAAC,EA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,IAAI,GAAG,IAAI,kBAAkB,CAAC,CAAA;IAEvF,MAAM,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;IAE7D,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE;QAC1B,MAAM;QACN,IAAI,EAAE,SAAmC;KAC1C,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,8CAA8C;AAE9C;;;;GAIG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,yBAAyB,CAAC,QAAQ,CAAC,CAAA;AAGzD;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,iBAAiB,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAA;AAGzE;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,iBAAiB,CAAC,UAAU,EAAE,sBAAsB,CAAC,CAAA;AAG7E;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,iBAAiB,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAA;AAG7E;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,iBAAiB,CAAC,aAAa,EAAE,gBAAgB,CAAC,CAAA"}
package/dist/Hash.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  /**
2
- * SHA256 content hashing via Node.js crypto, returning branded {@link ContentHash} values.
2
+ * SHA256 content hashing via Effect's platform `Crypto` service, returning branded {@link ContentHash} values.
3
3
  *
4
4
  * **Mental model**
5
5
  *
6
- * - **Effect-wrapped crypto**: {@link hashContent} and {@link hashBuffer} return
7
- * `Effect<ContentHash>` so hashing composes into pipelines without try/catch.
8
- * - **Sync escape hatch**: {@link hashContentSync} for contexts where Effect isn't needed.
6
+ * - **Service-backed crypto**: {@link hashContent} and {@link hashBuffer} use
7
+ * the `Crypto` service from Effect context, so applications provide the
8
+ * platform implementation at the runtime edge.
9
9
  *
10
10
  * **Common tasks**
11
11
  *
@@ -15,39 +15,37 @@
15
15
  *
16
16
  * @module
17
17
  */
18
+ import * as Crypto from "effect/Crypto";
18
19
  import * as Effect from "effect/Effect";
20
+ import type * as PlatformError from "effect/PlatformError";
19
21
  import { ContentHash } from "./Brand.js";
20
22
  /**
21
23
  * Compute SHA256 hash of a string.
22
24
  *
23
25
  * @example
24
26
  * ```typescript
25
- * import { hashContent } from "@knpkv/atlassian-common"
27
+ * import * as Crypto from "effect/Crypto"
26
28
  * import * as Effect from "effect/Effect"
29
+ * import { hashContent } from "@knpkv/atlassian-common"
27
30
  *
28
- * const hash = Effect.runSync(hashContent("hello world"))
31
+ * declare const crypto: Crypto.Crypto
32
+ * const hash = Effect.runSync(hashContent("hello world").pipe(Effect.provideService(Crypto.Crypto, crypto)))
29
33
  * // => "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"
30
34
  * ```
31
35
  *
32
36
  * @category Hash
33
37
  */
34
- export declare const hashContent: (content: string) => Effect.Effect<ContentHash>;
38
+ export declare const hashContent: (content: string) => Effect.Effect<ContentHash, PlatformError.PlatformError, Crypto.Crypto>;
35
39
  /**
36
40
  * Compute SHA256 hash of a buffer.
37
41
  *
38
42
  * @category Hash
39
43
  */
40
- export declare const hashBuffer: (buffer: Buffer | Uint8Array) => Effect.Effect<ContentHash>;
44
+ export declare const hashBuffer: (buffer: Uint8Array) => Effect.Effect<ContentHash, PlatformError.PlatformError, Crypto.Crypto>;
41
45
  /**
42
46
  * Check if two hashes are equal.
43
47
  *
44
48
  * @category Hash
45
49
  */
46
50
  export declare const hashEquals: (a: ContentHash, b: ContentHash) => boolean;
47
- /**
48
- * Synchronous version of hashContent for simple use cases.
49
- *
50
- * @category Hash
51
- */
52
- export declare const hashContentSync: (content: string) => ContentHash;
53
51
  //# sourceMappingURL=Hash.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Hash.d.ts","sourceRoot":"","sources":["../src/Hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;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GED
@@ -1,11 +1,11 @@
1
1
  /**
2
- * SHA256 content hashing via Node.js crypto, returning branded {@link ContentHash} values.
2
+ * SHA256 content hashing via Effect's platform `Crypto` service, returning branded {@link ContentHash} values.
3
3
  *
4
4
  * **Mental model**
5
5
  *
6
- * - **Effect-wrapped crypto**: {@link hashContent} and {@link hashBuffer} return
7
- * `Effect<ContentHash>` so hashing composes into pipelines without try/catch.
8
- * - **Sync escape hatch**: {@link hashContentSync} for contexts where Effect isn't needed.
6
+ * - **Service-backed crypto**: {@link hashContent} and {@link hashBuffer} use
7
+ * the `Crypto` service from Effect context, so applications provide the
8
+ * platform implementation at the runtime edge.
9
9
  *
10
10
  * **Common tasks**
11
11
  *
@@ -15,49 +15,43 @@
15
15
  *
16
16
  * @module
17
17
  */
18
+ import * as Crypto from "effect/Crypto";
18
19
  import * as Effect from "effect/Effect";
19
- import * as crypto from "node:crypto";
20
+ import * as Encoding from "effect/Encoding";
20
21
  import { ContentHash } from "./Brand.js";
22
+ const textEncoder = new TextEncoder();
23
+ const digestSha256 = (bytes) => Effect.gen(function* () {
24
+ const crypto = yield* Crypto.Crypto;
25
+ const digest = yield* crypto.digest("SHA-256", bytes);
26
+ return ContentHash(Encoding.encodeHex(digest));
27
+ });
21
28
  /**
22
29
  * Compute SHA256 hash of a string.
23
30
  *
24
31
  * @example
25
32
  * ```typescript
26
- * import { hashContent } from "@knpkv/atlassian-common"
33
+ * import * as Crypto from "effect/Crypto"
27
34
  * import * as Effect from "effect/Effect"
35
+ * import { hashContent } from "@knpkv/atlassian-common"
28
36
  *
29
- * const hash = Effect.runSync(hashContent("hello world"))
37
+ * declare const crypto: Crypto.Crypto
38
+ * const hash = Effect.runSync(hashContent("hello world").pipe(Effect.provideService(Crypto.Crypto, crypto)))
30
39
  * // => "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"
31
40
  * ```
32
41
  *
33
42
  * @category Hash
34
43
  */
35
- export const hashContent = (content) => Effect.sync(() => {
36
- const hash = crypto.createHash("sha256").update(content, "utf8").digest("hex");
37
- return ContentHash(hash);
38
- });
44
+ export const hashContent = (content) => digestSha256(textEncoder.encode(content));
39
45
  /**
40
46
  * Compute SHA256 hash of a buffer.
41
47
  *
42
48
  * @category Hash
43
49
  */
44
- export const hashBuffer = (buffer) => Effect.sync(() => {
45
- const hash = crypto.createHash("sha256").update(buffer).digest("hex");
46
- return ContentHash(hash);
47
- });
50
+ export const hashBuffer = (buffer) => digestSha256(buffer);
48
51
  /**
49
52
  * Check if two hashes are equal.
50
53
  *
51
54
  * @category Hash
52
55
  */
53
56
  export const hashEquals = (a, b) => a === b;
54
- /**
55
- * Synchronous version of hashContent for simple use cases.
56
- *
57
- * @category Hash
58
- */
59
- export const hashContentSync = (content) => {
60
- const hash = crypto.createHash("sha256").update(content, "utf8").digest("hex");
61
- return ContentHash(hash);
62
- };
63
57
  //# sourceMappingURL=Hash.js.map
package/dist/Hash.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Hash.js","sourceRoot":"","sources":["../src/Hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAExC;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,OAAe,EAA8B,EAAE,CACzE,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE;IACf,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAC9E,OAAO,WAAW,CAAC,IAAI,CAAC,CAAA;AAC1B,CAAC,CAAC,CAAA;AAEJ;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,MAA2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