aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2023-01-06 17:57:26 +0530
committerAkshay Nair <phenax5@gmail.com>2023-01-06 17:57:26 +0530
commit549440bf01ac5fa76d34d0b263f409a9802121e4 (patch)
tree3e19a0da914c1caf3a38c7321cfd588894253ed4
parent395b01feaadb896c1747696cd874bd70de727110 (diff)
downloadts-types-lang-549440bf01ac5fa76d34d0b263f409a9802121e4.tar.gz
ts-types-lang-549440bf01ac5fa76d34d0b263f409a9802121e4.zip
refactor: uses uuid instead of your shitty math.random bullshit
-rw-r--r--package.json4
-rw-r--r--src/index.ts8
-rw-r--r--src/runtime.ts16
-rw-r--r--yarn.lock15
4 files changed, 28 insertions, 15 deletions
diff --git a/package.json b/package.json
index a1e6d56..0028d3d 100644
--- a/package.json
+++ b/package.json
@@ -14,9 +14,11 @@
"@types/node": "^18.11.18",
"ts-morph": "^17.0.1",
"ts-node": "^10.9.1",
- "typescript": "^4.9.4"
+ "typescript": "^4.9.4",
+ "uuid": "^9.0.0"
},
"devDependencies": {
+ "@types/uuid": "^9.0.0",
"nodemon": "^2.0.20"
}
}
diff --git a/src/index.ts b/src/index.ts
index b8a69ac..aad0c00 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -13,7 +13,7 @@ export interface GetArgs extends EffectAtom<string[]> { }
export interface ReadLine extends EffectAtom<string> { }
-export interface JsExpr<_Expr extends string> extends EffectAtom<any> {}
+export interface JsExpr<_Expr extends string> extends EffectAtom<any> { }
export interface Program<Effs extends Effect, ExitCode extends number = 0> {
effects: Effs,
@@ -34,10 +34,6 @@ interface PrintK<Label extends string = ""> extends Kind1<unknown> {
return: Debug<Label, this['input']>
}
-// interface WithInputK extends Kind1<string> {
-// return: ChainIO<ReadLine, PrintK<this['input']>>
-// }
-
export type main = Program<[
ChainIO<GetArgs, PrintK>,
[1, 2, 3] extends infer Res ? Print<Res> : never,
@@ -46,6 +42,6 @@ export type main = Program<[
// ChainIO<ReadLine, WithInputK>,
ChainIO<ReadFile<"./default.nix">, PrintK>,
PutString<"Your name? ">,
- ChainIO<ReadLine, PrintK<"Hello,">>,
+ // ChainIO<ReadLine, PrintK<"Hello,">>,
]>
diff --git a/src/runtime.ts b/src/runtime.ts
index b3c49c3..f066df9 100644
--- a/src/runtime.ts
+++ b/src/runtime.ts
@@ -3,6 +3,7 @@ import path from 'path'
import { promises as fs } from 'fs'
import readline from 'readline';
import { stdout } from 'process';
+import { v4 as uuid } from 'uuid';
const rl = readline.createInterface({
input: process.stdin,
@@ -54,9 +55,6 @@ const addResult = (name: string, ty: string) => {
}
}
-const createHash = () =>
- Math.random().toFixed(8).slice(2)
-
const match = <K extends string, R>(k: K | undefined, pattern: { [key in K | '_']: () => R }) =>
k && pattern[k] ? pattern[k]() : pattern._()
@@ -68,7 +66,7 @@ const accumulateResults = async (effTyp: Type, node: Node): Promise<string[]> =>
const [pathTyp] = effTyp.getTypeArguments()
const filePath = JSON.parse(typeToString(pathTyp))
const contents = await fs.readFile(filePath, 'utf-8')
- const hash = createHash()
+ const hash = uuid()
addResult(hash, JSON.stringify(contents))
return [hash]
},
@@ -82,20 +80,20 @@ const accumulateResults = async (effTyp: Type, node: Node): Promise<string[]> =>
GetEnv: async () => {
const [envTyp] = effTyp.getTypeArguments()
const envName = JSON.parse(typeToString(envTyp))
- const hash = createHash()
+ const hash = uuid()
addResult(hash, `${JSON.stringify(process.env[envName] ?? '')}`)
return [hash]
},
GetArgs: async () => {
- const hash = createHash()
+ const hash = uuid()
addResult(hash, `${JSON.stringify(process.argv.slice(2))}`)
return [hash]
},
ReadLine: async () => {
const line = await readLineFromStdin()
- const hash = createHash()
+ const hash = uuid()
addResult(hash, `${JSON.stringify(line)}`)
return [hash]
},
@@ -104,7 +102,7 @@ const accumulateResults = async (effTyp: Type, node: Node): Promise<string[]> =>
const [exprTyp] = effTyp.getTypeArguments()
const exprStr = JSON.parse(typeToString(exprTyp))
const result = eval(`JSON.stringify(${exprStr})`)
- const hash = createHash()
+ const hash = uuid()
addResult(hash, `${result}`)
return [hash]
},
@@ -159,6 +157,8 @@ const evalAccumulator = async (effNode: Node, node: Node) => {
await evalAccumulator(updateEffNode, node)
},
+ ReplacePlaceholders: async () => { },
+
_: async () => {
console.log(effNode.print())
console.log('TTTT', typeToString(effTyp))
diff --git a/yarn.lock b/yarn.lock
index 8ac4b45..8bd5b34 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -83,6 +83,11 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.11.18.tgz#8dfb97f0da23c2293e554c5a50d61ef134d7697f"
integrity sha512-DHQpWGjyQKSHj3ebjFI/wRKcqQcdR+MoFBygntYOZytCqNfkd2ZC4ARDJ2DQqhjH5p85Nnd3jhUJIXrszFX/JA==
+"@types/uuid@^9.0.0":
+ version "9.0.0"
+ resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-9.0.0.tgz#53ef263e5239728b56096b0a869595135b7952d2"
+ integrity sha512-kr90f+ERiQtKWMz5rP32ltJ/BtULDI5RVO0uavn1HQUOwjx0R1h0rnDYNL0CepF1zL5bSY6FISAfd9tOdDhU5Q==
+
abbrev@1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8"
@@ -298,6 +303,11 @@ ms@^2.1.1:
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==
+nanoid@^4.0.0:
+ version "4.0.0"
+ resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-4.0.0.tgz#6e144dee117609232c3f415c34b0e550e64999a5"
+ integrity sha512-IgBP8piMxe/gf73RTQx7hmnhwz0aaEXYakvqZyE302IXW3HyVNhdNGC+O2MwMAVhLEnvXlvKtGbtJf6wvHihCg==
+
nodemon@^2.0.20:
version "2.0.20"
resolved "https://registry.yarnpkg.com/nodemon/-/nodemon-2.0.20.tgz#e3537de768a492e8d74da5c5813cb0c7486fc701"
@@ -440,6 +450,11 @@ undefsafe@^2.0.5:
resolved "https://registry.yarnpkg.com/undefsafe/-/undefsafe-2.0.5.tgz#38733b9327bdcd226db889fb723a6efd162e6e2c"
integrity sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==
+uuid@^9.0.0:
+ version "9.0.0"
+ resolved "https://registry.yarnpkg.com/uuid/-/uuid-9.0.0.tgz#592f550650024a38ceb0c562f2f6aa435761efb5"
+ integrity sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==
+
v8-compile-cache-lib@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz#6336e8d71965cb3d35a1bbb7868445a7c05264bf"