@helios-lang/contract-utils 0.2.73 → 0.2.75

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.
package/package.json CHANGED
@@ -1,9 +1,16 @@
1
1
  {
2
2
  "name": "@helios-lang/contract-utils",
3
- "version": "0.2.73",
3
+ "version": "0.2.75",
4
4
  "description": "Convenience and type-safety utilities for using Helios validators from within Typescript",
5
5
  "main": "src/index.js",
6
6
  "types": "types/index.d.ts",
7
+ "exports": {
8
+ ".": "./src/index.js",
9
+ "./set-fs-build-cache": "./src/context/set-fs-build-cache.js"
10
+ },
11
+ "sideEffects": [
12
+ "./src/context/set-fs-build-cache.js"
13
+ ],
7
14
  "type": "module",
8
15
  "bin": {
9
16
  "hl2ts": "src/hl2ts.js"
@@ -153,92 +153,3 @@ class ContractContextCache {
153
153
  }
154
154
 
155
155
  export const contractContextCache = new ContractContextCache()
156
-
157
- /**
158
- * @typedef {"fs"} BuildCacheKind
159
- */
160
-
161
- /**
162
- * @param {BuildCacheKind} kind
163
- */
164
- export function setBuildCache(kind) {
165
- if (kind === "fs") {
166
- contractContextCache.explicitCache = new FileSystemCache()
167
- } else {
168
- throw new Error("invalid build cache props")
169
- }
170
- }
171
-
172
- // uses same storage strategy as esbuild-plugin
173
- /**
174
- * @implements {ExplicitCache}
175
- */
176
- class FileSystemCache {
177
- /**
178
- * @private
179
- * @type {typeof import("node:fs")}
180
- */
181
- fs
182
-
183
- /**
184
- * @private
185
- * @type {typeof import("node:os")}
186
- */
187
- os
188
-
189
- /**
190
- * @private
191
- * @type {typeof import("node:path")}
192
- */
193
- path
194
-
195
- /**
196
- * @private
197
- * @type {string}
198
- */
199
- cacheDir
200
-
201
- constructor() {
202
- this.fs = require("node:fs")
203
- this.os = require("node:os")
204
- this.path = require("node:path")
205
- this.cacheDir = this.path.join(this.os.tmpdir(), "helios-cache")
206
-
207
- if (!this.fs.existsSync(this.cacheDir)) {
208
- this.fs.mkdirSync(this.cacheDir, {
209
- recursive: true
210
- })
211
- }
212
- }
213
-
214
- /**
215
- * @private
216
- * @param {string} key
217
- */
218
- genPath(key) {
219
- return this.path.join(this.cacheDir, key + ".json")
220
- }
221
-
222
- /**
223
- * @param {string} key
224
- */
225
- has(key) {
226
- return this.fs.existsSync(this.genPath(key))
227
- }
228
-
229
- /**
230
- * @param {string} key
231
- * @returns {JsonSafe}
232
- */
233
- get(key) {
234
- return JSON.parse(this.fs.readFileSync(this.genPath(key)).toString())
235
- }
236
-
237
- /**
238
- * @param {string} key
239
- * @param {JsonSafe} obj
240
- */
241
- set(key, obj) {
242
- this.fs.writeFileSync(this.genPath(key), JSON.stringify(obj))
243
- }
244
- }
@@ -1,5 +1,5 @@
1
1
  export { ContractContextBuilder } from "./ContractContextBuilder.js"
2
- export { contractContextCache, setBuildCache } from "./ContractContextCache.js"
2
+ export { contractContextCache } from "./ContractContextCache.js"
3
3
 
4
4
  /**
5
5
  * @template {{[name: string]: import("../codegen/index.js").LoadedValidator}} Vs
@@ -0,0 +1,88 @@
1
+ import { contractContextCache } from "./ContractContextCache.js"
2
+
3
+ /**
4
+ * @typedef {import("./ContractContextCache.js").ExplicitCache} ExplicitCache
5
+ */
6
+
7
+ // uses same storage strategy as esbuild-plugin
8
+ /**
9
+ * @implements {ExplicitCache}
10
+ */
11
+ class FileSystemCache {
12
+ /**
13
+ * @private
14
+ * @type {typeof import("node:fs")}
15
+ */
16
+ fs
17
+
18
+ /**
19
+ * @private
20
+ * @type {typeof import("node:os")}
21
+ */
22
+ os
23
+
24
+ /**
25
+ * @private
26
+ * @type {typeof import("node:path")}
27
+ */
28
+ path
29
+
30
+ /**
31
+ * @private
32
+ * @type {string}
33
+ */
34
+ cacheDir
35
+
36
+ constructor() {
37
+ // hopefully this loads before starting the context build
38
+ Promise.all([
39
+ import("node:fs"),
40
+ import("node:os"),
41
+ import("node:path")
42
+ ]).then(([fs, os, path]) => {
43
+ this.fs = fs
44
+ this.os = os
45
+ this.path = path
46
+ this.cacheDir = this.path.join(this.os.tmpdir(), "helios-cache")
47
+
48
+ if (!this.fs.existsSync(this.cacheDir)) {
49
+ this.fs.mkdirSync(this.cacheDir, {
50
+ recursive: true
51
+ })
52
+ }
53
+ })
54
+ }
55
+
56
+ /**
57
+ * @private
58
+ * @param {string} key
59
+ */
60
+ genPath(key) {
61
+ return this.path.join(this.cacheDir, key + ".json")
62
+ }
63
+
64
+ /**
65
+ * @param {string} key
66
+ */
67
+ has(key) {
68
+ return this.fs.existsSync(this.genPath(key))
69
+ }
70
+
71
+ /**
72
+ * @param {string} key
73
+ * @returns {JsonSafe}
74
+ */
75
+ get(key) {
76
+ return JSON.parse(this.fs.readFileSync(this.genPath(key)).toString())
77
+ }
78
+
79
+ /**
80
+ * @param {string} key
81
+ * @param {JsonSafe} obj
82
+ */
83
+ set(key, obj) {
84
+ this.fs.writeFileSync(this.genPath(key), JSON.stringify(obj))
85
+ }
86
+ }
87
+
88
+ contractContextCache.explicitCache = new FileSystemCache()
@@ -1,12 +1,4 @@
1
- /**
2
- * @typedef {"fs"} BuildCacheKind
3
- */
4
- /**
5
- * @param {BuildCacheKind} kind
6
- */
7
- export function setBuildCache(kind: BuildCacheKind): void;
8
1
  export const contractContextCache: ContractContextCache;
9
- export type BuildCacheKind = "fs";
10
2
  export type UplcData = import("@helios-lang/uplc").UplcData;
11
3
  export type UplcProgram = import("@helios-lang/uplc").UplcProgram;
12
4
  export type LoadedModule = import("../codegen/LoadedModule.js").LoadedModule;
@@ -1 +1 @@
1
- {"version":3,"file":"ContractContextCache.d.ts","sourceRoot":"","sources":["../../src/context/ContractContextCache.js"],"names":[],"mappings":"AA4JA;;GAEG;AAEH;;GAEG;AACH,oCAFW,cAAc,QAQxB;AAfD,wDAA8D;6BAGjD,IAAI;uBAvJJ,OAAO,mBAAmB,EAAE,QAAQ;0BACpC,OAAO,mBAAmB,EAAE,WAAW;2BACvC,OAAO,4BAA4B,EAAE,YAAY;8BACjD,OAAO,+BAA+B,EAAE,eAAe;yBACvD,OAAO,iBAAiB,EAAE,UAAU;6BACpC,OAAO,iBAAiB,EAAE,cAAc;sCACxC,OAAO,iBAAiB,EAAE,uBAAuB;uCACjD,OAAO,iBAAiB,EAAE,wBAAwB;4BAIlD;IACR,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;IACzB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAAA;IAC1B,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAA;CACxC;AAhBJ;;;;;;;;;GASG;AAEH;;;;;;GAMG;AAEH;IACI;;;;OAIG;IACH,wBAAe;IAEf;;;;OAIG;IACH,eAFU,MAAM,CAAC,aAAa,CAAC,CAElB;IAEb;;;;OAIG;IACH,UAAC;IAED;;;OAGG;IACH,gBAAO;IAQP,eAEC;IAED;;;;;;;;;;;OAWG;IACH,mBAVW;QACN,OAAO,EAAE,MAAM,CAAA;QACf,KAAK,EAAE,OAAO,CAAA;QACd,SAAS,EAAE,OAAO,CAAA;QAClB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;QAC3C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;QACrC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;KACrC,GACS,MAAM,CA0BlB;IAED;;OAEG;IACH,WAFW,cAAc,EAAE,QAI1B;IAED;;;OAGG;IACH,SAHW,MAAM,SACN,UAAU,QAQpB;IAED;;;OAGG;IACH,SAHW,MAAM,GACJ,MAAM,CAAC,UAAU,CAAC,CAuB9B;IAED;;OAEG;IACH,UAFY,cAAc,EAAE,CAI3B;CACJ"}
1
+ {"version":3,"file":"ContractContextCache.d.ts","sourceRoot":"","sources":["../../src/context/ContractContextCache.js"],"names":[],"mappings":"AA0JA,wDAA8D;uBApJjD,OAAO,mBAAmB,EAAE,QAAQ;0BACpC,OAAO,mBAAmB,EA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ContractContextCache.js";
2
3
  export type ContractContext<Vs extends {
3
4
  [name: string]: import("../codegen/index.js").LoadedValidator;
4
5
  }, Ms extends {
5
6
  [name: string]: import("../codegen/index.js").LoadedModule;
6
7
  }> = import("./ContractContext.js").ContractContext<Vs, Ms>;
7
- export { contractContextCache, setBuildCache } from "./ContractContextCache.js";
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.js"],"names":[],"mappings":";4BAI+E,EAAE,SAApE;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,qBAAqB,EAAE,eAAe,CAAA;CAAE,EACF,EAAE,SAAjE;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,qBAAqB,EAAE,YAAY,CAAA;CAAE,IAC9D,OAAO,sBAAsB,EAAE,eAAe,CAAC,EAAE,EAAE,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.js"],"names":[],"mappings":";;4BAI+E,EAAE,SAApE;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,qBAAqB,EAAE,eAAe,CAAA;CAAE,EACF,EAAE,SAAjE;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,qBAAqB,EAAE,YAAY,CAAA;CAAE,IAC9D,OAAO,sBAAsB,EAAE,eAAe,CAAC,EAAE,EAAE,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export type ExplicitCache = import("./ContractContextCache.js").ExplicitCache;
2
+ //# sourceMappingURL=set-fs-build-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set-fs-build-cache.d.ts","sourceRoot":"","sources":["../../src/context/set-fs-build-cache.js"],"names":[],"mappings":"4BAGa,OAAO,2BAA2B,EAAE,aAAa"}