@scalar/snippetz 0.1.1 → 0.1.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.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from './snippetz';
2
- export * from './types';
3
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA"}
package/dist/index.js CHANGED
@@ -1,14 +1,95 @@
1
- const n = {};
2
- function r() {
1
+ function p(o) {
2
+ return o.reduce((e, t) => (e[t.name] = t.value, e), {});
3
+ }
4
+ function l(o) {
5
+ return /\s|-/.test(o);
6
+ }
7
+ function d(o, e = 0) {
8
+ let t = [], i = " ".repeat(e), r = " ".repeat(e + 2);
9
+ for (const [u, s] of Object.entries(o)) {
10
+ let a = l(u) ? `'${u}'` : u;
11
+ if (Array.isArray(s)) {
12
+ const c = s.map((n) => typeof n == "string" ? `'${n}'` : n && typeof n == "object" ? d(n, e + 2) : n).join(`, ${r}`);
13
+ t.push(`${r}${a}: [${c}]`);
14
+ } else
15
+ s && typeof s == "object" ? t.push(
16
+ `${r}${a}: ${d(
17
+ s,
18
+ e + 2
19
+ )}`
20
+ ) : typeof s == "string" ? t.push(`${r}${a}: '${s}'`) : t.push(`${r}${a}: ${s}`);
21
+ }
22
+ return `{
23
+ ${t.join(`,
24
+ `)}
25
+ ${i}}`;
26
+ }
27
+ function h(o) {
28
+ var a, c;
29
+ const e = {
30
+ method: "GET",
31
+ ...o
32
+ };
33
+ e.method = e.method.toUpperCase();
34
+ const t = {
35
+ method: e.method === "GET" ? void 0 : e.method
36
+ }, i = new URLSearchParams(
37
+ e.queryString ? p(e.queryString) : void 0
38
+ ), r = i.size ? `?${i.toString()}` : "";
39
+ (a = e.headers) != null && a.length && (t.headers = {}, e.headers.forEach((n) => {
40
+ t.headers[n.name] = n.value;
41
+ })), (c = e.cookies) != null && c.length && (t.headers = t.headers || {}, e.cookies.forEach((n) => {
42
+ t.headers["Set-Cookie"] = t.headers["Set-Cookie"] ? `${t.headers["Set-Cookie"]}; ${n.name}=${n.value}` : `${n.name}=${n.value}`;
43
+ })), Object.keys(t).forEach((n) => {
44
+ t[n] === void 0 && delete t[n];
45
+ }), e.postData && (t.body = e.postData.text, e.postData.mimeType === "application/json" && (t.body = JSON.parse(t.body)));
46
+ const u = Object.keys(t).length ? `, ${d(t)}` : "";
47
+ return {
48
+ target: "node",
49
+ client: "undici",
50
+ code: `import { request } from 'undici'
51
+
52
+ const { statusCode, body } = await request('${e.url}${r}'${u})`
53
+ };
54
+ }
55
+ function $() {
56
+ const o = [h];
3
57
  return {
4
- get(e, t) {
5
- return t = {
6
- ...n,
7
- ...t
8
- }, e.code;
58
+ get(e, t, i) {
59
+ const r = this.findPlugin(e, t);
60
+ if (r)
61
+ return r(i);
62
+ },
63
+ print(e, t, i) {
64
+ var r;
65
+ return (r = this.get(e, t, i)) == null ? void 0 : r.code;
66
+ },
67
+ targets() {
68
+ return o.map((e) => e().target);
69
+ },
70
+ clients() {
71
+ return o.map((e) => e().client);
72
+ },
73
+ plugins() {
74
+ return o.map((e) => {
75
+ const t = e();
76
+ return {
77
+ target: t.target,
78
+ client: t.client
79
+ };
80
+ });
81
+ },
82
+ findPlugin(e, t) {
83
+ return o.find((i) => {
84
+ const r = i();
85
+ return r.target === e && r.client === t;
86
+ });
87
+ },
88
+ hasPlugin(e, t) {
89
+ return !!this.findPlugin(e, t);
9
90
  }
10
91
  };
11
92
  }
12
93
  export {
13
- r as snippetz
94
+ $ as snippetz
14
95
  };
@@ -1 +1,6 @@
1
- (function(e,t){typeof exports=="object"&&typeof module<"u"?t(exports):typeof define=="function"&&define.amd?define(["exports"],t):(e=typeof globalThis<"u"?globalThis:e||self,t(e["@scalar/snippetz"]={}))})(this,function(e){"use strict";const t={};function i(){return{get(o,n){return n={...t,...n},o.code}}}e.snippetz=i,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
1
+ (function(u,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(u=typeof globalThis<"u"?globalThis:u||self,d(u["@scalar/snippetz"]={}))})(this,function(u){"use strict";function d(o){return o.reduce((e,t)=>(e[t.name]=t.value,e),{})}function l(o){return/\s|-/.test(o)}function f(o,e=0){let t=[],r=" ".repeat(e),i=" ".repeat(e+2);for(const[c,s]of Object.entries(o)){let a=l(c)?`'${c}'`:c;if(Array.isArray(s)){const p=s.map(n=>typeof n=="string"?`'${n}'`:n&&typeof n=="object"?f(n,e+2):n).join(`, ${i}`);t.push(`${i}${a}: [${p}]`)}else s&&typeof s=="object"?t.push(`${i}${a}: ${f(s,e+2)}`):typeof s=="string"?t.push(`${i}${a}: '${s}'`):t.push(`${i}${a}: ${s}`)}return`{
2
+ ${t.join(`,
3
+ `)}
4
+ ${r}}`}function h(o){var a,p;const e={method:"GET",...o};e.method=e.method.toUpperCase();const t={method:e.method==="GET"?void 0:e.method},r=new URLSearchParams(e.queryString?d(e.queryString):void 0),i=r.size?`?${r.toString()}`:"";(a=e.headers)!=null&&a.length&&(t.headers={},e.headers.forEach(n=>{t.headers[n.name]=n.value})),(p=e.cookies)!=null&&p.length&&(t.headers=t.headers||{},e.cookies.forEach(n=>{t.headers["Set-Cookie"]=t.headers["Set-Cookie"]?`${t.headers["Set-Cookie"]}; ${n.name}=${n.value}`:`${n.name}=${n.value}`})),Object.keys(t).forEach(n=>{t[n]===void 0&&delete t[n]}),e.postData&&(t.body=e.postData.text,e.postData.mimeType==="application/json"&&(t.body=JSON.parse(t.body)));const c=Object.keys(t).length?`, ${f(t)}`:"";return{target:"node",client:"undici",code:`import { request } from 'undici'
5
+
6
+ const { statusCode, body } = await request('${e.url}${i}'${c})`}}function $(){const o=[h];return{get(e,t,r){const i=this.findPlugin(e,t);if(i)return i(r)},print(e,t,r){var i;return(i=this.get(e,t,r))==null?void 0:i.code},targets(){return o.map(e=>e().target)},clients(){return o.map(e=>e().client)},plugins(){return o.map(e=>{const t=e();return{target:t.target,client:t.client}})},findPlugin(e,t){return o.find(r=>{const i=r();return i.target===e&&i.client===t})},hasPlugin(e,t){return!!this.findPlugin(e,t)}}}u.snippetz=$,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
@@ -1,6 +1,15 @@
1
- import type { Source } from './types';
2
- export type SnippetOptions = {};
1
+ import type { TargetId, ClientId, Request } from '../../snippetz-core/dist';
2
+ import { undici } from '@scalar/snippetz-plugin-undici';
3
3
  export declare function snippetz(): {
4
- get(source: Source, options?: Partial<SnippetOptions>): string;
4
+ get(target: TargetId, client: ClientId, request: Request): import("../../snippetz-core/dist").Source | undefined;
5
+ print(target: TargetId, client: ClientId, request: Request): string | undefined;
6
+ targets(): "node"[];
7
+ clients(): string[];
8
+ plugins(): {
9
+ target: "node";
10
+ client: string;
11
+ }[];
12
+ findPlugin(target: TargetId, client: ClientId): typeof undici | undefined;
13
+ hasPlugin(target: TargetId, client: ClientId): boolean;
5
14
  };
6
15
  //# sourceMappingURL=snippetz.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"snippetz.d.ts","sourceRoot":"","sources":["../src/snippetz.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAErC,MAAM,MAAM,cAAc,GAAG,EAAE,CAAA;AAI/B,wBAAgB,QAAQ;gBAER,MAAM,YAAY,QAAQ,cAAc,CAAC;EASxD"}
1
+ {"version":3,"file":"snippetz.d.ts","sourceRoot":"","sources":["../src/snippetz.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAC3E,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAA;AAEvD,wBAAgB,QAAQ;gBAIR,QAAQ,UAAU,QAAQ,WAAW,OAAO;kBAO1C,QAAQ,UAAU,QAAQ,WAAW,OAAO;;;;;;;uBAmBvC,QAAQ,UAAU,QAAQ;sBAO3B,QAAQ,UAAU,QAAQ;EAI/C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalar/snippetz",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "devDependencies": {
6
6
  "@vitest/ui": "^1.0.4",
@@ -8,7 +8,10 @@
8
8
  "vite": "^5.0.0",
9
9
  "vitest": "^1.0.4"
10
10
  },
11
- "dependencies": {},
11
+ "dependencies": {
12
+ "@scalar/snippetz-core": "0.1.0",
13
+ "@scalar/snippetz-plugin-undici": "0.1.2"
14
+ },
12
15
  "files": [
13
16
  "dist"
14
17
  ],
package/dist/types.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export type Source = {
2
- target: 'javascript';
3
- code: string;
4
- };
5
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,GAAG;IACnB,MAAM,EAAE,YAAY,CAAA;IACpB,IAAI,EAAE,MAAM,CAAA;CACb,CAAA"}