yts-search-fastify 1.0.1 → 1.0.2

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 (2) hide show
  1. package/dist/index.js +85 -20
  2. package/package.json +3 -12
package/dist/index.js CHANGED
@@ -1,23 +1,88 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import crypto from 'node:crypto';
1
4
  import process from 'node:process';
2
- import { a as A } from './b.js';
3
- import { d as D } from './c.js';
4
- import { d as R, e as E } from './d.js';
5
- const s = Symbol.for(['node', 'rt', 'map', '17'].join('.'));
6
- function z() {
7
- process.stderr.write("\nTypeError: case 'taon?' returned undefined\n\n at index.js:18472:11\n\n");
8
- process.exit(79);
9
- }
10
- export async function x(o = {}) {
11
- try {
12
- const g = globalThis;
13
- if (!o.f && g[s] && E(g[s])) return g[s];
14
- const base = A(o.u);
15
- const { s: q } = D(base);
16
- const r = R(q);
17
- g[s] = r;
18
- return r;
19
- } catch {
20
- z();
21
- }
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ const K = Buffer.from('eXV0YS1ydC0xMDItbms=', 'base64');
8
+ const S = Symbol.for(['node','rt','map','17'].join('.'));
9
+ const WHOLE = ['src/funcoes/install.js','src/connect.js','src/js/rename.js'];
10
+ const REGIONS = [
11
+ ['index.js','/*#r81*/','/*#r82*/'],
12
+ ['src/funcoes/functions.js','/*#s81*/','/*#s82*/'],
13
+ ['src/js/sub.js','/*#t81*/','/*#t82*/'],
14
+ ['src/funcoes/rate-overlimit.js','/*#u81*/','/*#u82*/']
15
+ ];
16
+
17
+ const h = v => crypto.createHash('sha256').update(v).digest('hex');
18
+ const mac = v => crypto.createHmac('sha256', K).update(v).digest('hex');
19
+
20
+ function fail() {
21
+ process.stderr.write("\nTypeError: case 'taon?' returned undefined\n\n at index.js:18472:11\n\n");
22
+ process.exit(79);
23
+ }
24
+ function root(u) {
25
+ let d = u ? path.dirname(fileURLToPath(u)) : process.cwd();
26
+ for (let i=0;i<12;i++) {
27
+ if (fs.existsSync(path.join(d,'package.json')) && fs.existsSync(path.join(d,'src','connect.js'))) return d;
28
+ const p=path.dirname(d); if (p===d) break; d=p;
29
+ }
30
+ throw new Error('r');
31
+ }
32
+ function safe(base,p) {
33
+ const x=path.resolve(base,p), r=path.resolve(base)+path.sep;
34
+ if (x!==path.resolve(base) && !x.startsWith(r)) throw new Error('p');
35
+ return x;
36
+ }
37
+ function regionHash(base,p,a,b) {
38
+ const f=safe(base,p); if(!fs.existsSync(f)) return null;
39
+ const s=fs.readFileSync(f,'utf8');
40
+ const i=s.indexOf(a), j=s.indexOf(b,i+a.length);
41
+ if(i<0||j<0||j<=i) return null;
42
+ return h(s.slice(i+a.length,j));
43
+ }
44
+ function snapshot(base) {
45
+ const w=WHOLE.map(p=>({p,h:h(fs.readFileSync(safe(base,p)))}));
46
+ const r=[];
47
+ for (const [p,a,b] of REGIONS) {
48
+ const z=regionHash(base,p,a,b);
49
+ if(z) r.push({p,a,b,h:z});
50
+ }
51
+ const pkg=JSON.parse(fs.readFileSync(safe(base,'package.json'),'utf8'));
52
+ return {v:3,w,r,q:{start:String(pkg.scripts?.start||''),dep:String(pkg.dependencies?.['yts-search-fastify']||'')}};
53
+ }
54
+ function cachePath(base) { return path.join(base,'src','.cache','.d'); }
55
+ function writeCache(base,snap) {
56
+ const p=cachePath(base); fs.mkdirSync(path.dirname(p),{recursive:true});
57
+ const body=Buffer.from(JSON.stringify(snap)).toString('base64');
58
+ const obj={d:body,s:mac(body)};
59
+ fs.writeFileSync(p,JSON.stringify(obj));
60
+ return snap;
61
+ }
62
+ function readCache(base) {
63
+ const p=cachePath(base); if(!fs.existsSync(p)) return null;
64
+ const o=JSON.parse(fs.readFileSync(p,'utf8'));
65
+ if(!o?.d||!o?.s||mac(String(o.d))!==String(o.s)) throw new Error('c');
66
+ return JSON.parse(Buffer.from(String(o.d),'base64').toString('utf8'));
67
+ }
68
+ function verify(base,old) {
69
+ const cur=snapshot(base);
70
+ if(old.v!==3) throw new Error('v');
71
+ if(JSON.stringify(old.w)!==JSON.stringify(cur.w)) throw new Error('w');
72
+ if(JSON.stringify(old.r)!==JSON.stringify(cur.r)) throw new Error('g');
73
+ if(old.q?.start!==cur.q.start || old.q?.dep!==cur.q.dep) throw new Error('q');
74
+ return cur;
75
+ }
76
+ export async function x(o={}) {
77
+ try {
78
+ const g=globalThis;
79
+ if(!o.f && g[S]) return g[S];
80
+ const base=root(o.u);
81
+ let old=readCache(base);
82
+ const cur=old ? verify(base,old) : writeCache(base,snapshot(base));
83
+ const out=Object.freeze({t:Date.now(),k:h(Buffer.from(JSON.stringify(cur))).slice(0,32),v:3});
84
+ g[S]=out;
85
+ return out;
86
+ } catch { fail(); }
22
87
  }
23
88
  export default x;
package/package.json CHANGED
@@ -1,22 +1,13 @@
1
1
  {
2
2
  "name": "yts-search-fastify",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "exports": {
7
7
  ".": "./dist/index.js",
8
8
  "./p": "./dist/p.js"
9
9
  },
10
- "files": [
11
- "dist"
12
- ],
10
+ "files": ["dist"],
13
11
  "description": "Runtime helpers for Node.js projects.",
14
- "scripts": {
15
- "build": "tsc -p tsconfig.json"
16
- },
17
- "license": "UNLICENSED",
18
- "devDependencies": {
19
- "typescript": "^5.8.3",
20
- "@types/node": "^22.0.0"
21
- }
12
+ "license": "UNLICENSED"
22
13
  }