@scalar/snippetz 0.2.3 → 0.2.5
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/README.md +2 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/types.d.ts +21 -3
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.test-d.d.ts +2 -0
- package/dist/core/types.test-d.d.ts.map +1 -0
- package/dist/core/utils/arrayToObject.d.ts +6 -1
- package/dist/core/utils/arrayToObject.d.ts.map +1 -1
- package/dist/core/utils/arrayToObject.js +6 -1
- package/dist/core/utils/needsQuotes.d.ts +7 -0
- package/dist/core/utils/needsQuotes.d.ts.map +1 -0
- package/dist/core/utils/needsQuotes.js +10 -0
- package/dist/core/utils/objectToString.d.ts +5 -0
- package/dist/core/utils/objectToString.d.ts.map +1 -1
- package/dist/core/utils/objectToString.js +7 -2
- package/dist/plugins/js/fetch/fetch.d.ts +8 -1
- package/dist/plugins/js/fetch/fetch.d.ts.map +1 -1
- package/dist/plugins/js/fetch/fetch.js +3 -0
- package/dist/plugins/js/ofetch/ofetch.d.ts +8 -1
- package/dist/plugins/js/ofetch/ofetch.d.ts.map +1 -1
- package/dist/plugins/js/ofetch/ofetch.js +6 -1
- package/dist/plugins/node/fetch/fetch.d.ts +8 -1
- package/dist/plugins/node/fetch/fetch.d.ts.map +1 -1
- package/dist/plugins/node/fetch/fetch.js +3 -0
- package/dist/plugins/node/ofetch/ofetch.d.ts +8 -1
- package/dist/plugins/node/ofetch/ofetch.d.ts.map +1 -1
- package/dist/plugins/node/ofetch/ofetch.js +6 -1
- package/dist/plugins/node/undici/undici.d.ts +8 -1
- package/dist/plugins/node/undici/undici.d.ts.map +1 -1
- package/dist/plugins/node/undici/undici.js +3 -0
- package/dist/plugins/shell/curl/curl.d.ts +10 -0
- package/dist/plugins/shell/curl/curl.d.ts.map +1 -0
- package/dist/plugins/shell/curl/curl.js +105 -0
- package/dist/plugins/shell/curl/index.d.ts +2 -0
- package/dist/plugins/shell/curl/index.d.ts.map +1 -0
- package/dist/plugins/shell/curl/index.js +1 -0
- package/dist/snippetz.d.ts +9 -9
- package/dist/snippetz.d.ts.map +1 -1
- package/dist/snippetz.js +2 -1
- package/package.json +25 -9
- package/dist/core/utils/isKeyNeedsQuotes.d.ts +0 -2
- package/dist/core/utils/isKeyNeedsQuotes.d.ts.map +0 -1
- package/dist/core/utils/isKeyNeedsQuotes.js +0 -5
package/README.md
CHANGED
package/dist/core/index.d.ts
CHANGED
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,qBAAqB,CAAA;AACnC,cAAc,wBAAwB,CAAA;AAEtC,cAAc,SAAS,CAAA"}
|
package/dist/core/index.js
CHANGED
package/dist/core/types.d.ts
CHANGED
|
@@ -1,12 +1,30 @@
|
|
|
1
1
|
export type { Request } from 'har-format';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Clients {
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
export type AddClient<T extends string, C extends string> = {
|
|
7
|
+
[K in `${T}/${C}`]: C;
|
|
8
|
+
};
|
|
9
|
+
export type TargetId = keyof Clients & string extends `${infer T}/${string}` ? T : never;
|
|
10
|
+
export type ClientId<T extends TargetId> = Clients[keyof Clients & `${T}/${string}`];
|
|
11
|
+
/** What any plugins needs to return */
|
|
2
12
|
export type Source = {
|
|
3
13
|
/** The language or environment. */
|
|
4
14
|
target: TargetId;
|
|
5
15
|
/** The identifier of the client. */
|
|
6
|
-
client: ClientId
|
|
16
|
+
client: ClientId<TargetId>;
|
|
7
17
|
/** The actual source code. */
|
|
8
18
|
code: string;
|
|
9
19
|
};
|
|
10
|
-
|
|
11
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Optional configuration for any plugin
|
|
22
|
+
*/
|
|
23
|
+
export type PluginConfiguration = {
|
|
24
|
+
/** Credentials to add HTTP Basic Authentication */
|
|
25
|
+
auth?: {
|
|
26
|
+
username: string;
|
|
27
|
+
password: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
12
30
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/core/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEzC,MAAM,MAAM,MAAM,GAAG;IACnB,mCAAmC;IACnC,MAAM,EAAE,QAAQ,CAAA;IAChB,oCAAoC;IACpC,MAAM,EAAE,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEzC,OAAO,CAAC,MAAM,CAAC;IAEb,UAAU,OAAO;KAAG;CACrB;AAED,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,IAAI;KACzD,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC;CACtB,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG,MAAM,OAAO,GAAG,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,MAAM,EAAE,GACxE,CAAC,GACD,KAAK,CAAA;AAET,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,QAAQ,IAAI,OAAO,CAAC,MAAM,OAAO,GAC9D,GAAG,CAAC,IAAI,MAAM,EAAE,CAAC,CAAA;AAEnB,uCAAuC;AACvC,MAAM,MAAM,MAAM,GAAG;IACnB,mCAAmC;IACnC,MAAM,EAAE,QAAQ,CAAA;IAChB,oCAAoC;IACpC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAA;IAC1B,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,mDAAmD;IACnD,IAAI,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAA;CAC9C,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.test-d.d.ts","sourceRoot":"","sources":["../../src/core/types.test-d.ts"],"names":[],"mappings":""}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Converts an array of name/value pairs into an object with those mappings
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* arrayToObject([{ name: 'foo', value: 'bar' }]) // => { foo: 'bar' }
|
|
6
|
+
*/
|
|
2
7
|
export declare function arrayToObject(items: any): any;
|
|
3
8
|
//# sourceMappingURL=arrayToObject.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arrayToObject.d.ts","sourceRoot":"","sources":["../../../src/core/utils/arrayToObject.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"arrayToObject.d.ts","sourceRoot":"","sources":["../../../src/core/utils/arrayToObject.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,GAAG,OAKvC"}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Converts an array of name/value pairs into an object with those mappings
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* arrayToObject([{ name: 'foo', value: 'bar' }]) // => { foo: 'bar' }
|
|
6
|
+
*/
|
|
2
7
|
function arrayToObject(items) {
|
|
3
8
|
return items.reduce((acc, item) => {
|
|
4
9
|
acc[item.name] = item.value;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"needsQuotes.d.ts","sourceRoot":"","sources":["../../../src/core/utils/needsQuotes.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,WAEtC"}
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts an object into a string representation with proper formatting and indentation
|
|
3
|
+
*
|
|
4
|
+
* Handles nested objects, arrays, and special string values
|
|
5
|
+
*/
|
|
1
6
|
export declare function objectToString(obj: Record<string, any>, indent?: number): string;
|
|
2
7
|
//# sourceMappingURL=objectToString.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"objectToString.d.ts","sourceRoot":"","sources":["../../../src/core/utils/objectToString.ts"],"names":[],"mappings":"AAEA,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,SAAI,GAAG,MAAM,CAyD3E"}
|
|
1
|
+
{"version":3,"file":"objectToString.d.ts","sourceRoot":"","sources":["../../../src/core/utils/objectToString.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,SAAI,GAAG,MAAM,CAyD3E"}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { needsQuotes } from './needsQuotes.js';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Converts an object into a string representation with proper formatting and indentation
|
|
5
|
+
*
|
|
6
|
+
* Handles nested objects, arrays, and special string values
|
|
7
|
+
*/
|
|
3
8
|
function objectToString(obj, indent = 0) {
|
|
4
9
|
const parts = [];
|
|
5
10
|
const indentation = ' '.repeat(indent);
|
|
6
11
|
const innerIndentation = ' '.repeat(indent + 2);
|
|
7
12
|
for (const [key, value] of Object.entries(obj)) {
|
|
8
|
-
const formattedKey =
|
|
13
|
+
const formattedKey = needsQuotes(key) ? `'${key}'` : key;
|
|
9
14
|
if (Array.isArray(value)) {
|
|
10
15
|
const arrayString = value
|
|
11
16
|
.map((item) => {
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
import { type Request, type Source } from '../../../core/index.js';
|
|
1
|
+
import { type AddClient, type Request, type Source } from '../../../core/index.js';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Clients extends AddClient<'js', 'fetch'> {
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* js/fetch
|
|
8
|
+
*/
|
|
2
9
|
export declare function fetch(request?: Partial<Request>): Source;
|
|
3
10
|
//# sourceMappingURL=fetch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/js/fetch/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,MAAM,EAGZ,MAAM,eAAe,CAAA;AAEtB,wBAAgB,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,MAAM,CA6ExD"}
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/js/fetch/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,OAAO,EACZ,KAAK,MAAM,EAGZ,MAAM,eAAe,CAAA;AAEtB,OAAO,CAAC,MAAM,CAAC;IAEb,UAAU,OAAQ,SAAQ,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC;KAAG;CACtD;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,MAAM,CA6ExD"}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
import { type Request, type Source } from '../../../core/index.js';
|
|
1
|
+
import { type AddClient, type Request, type Source } from '../../../core/index.js';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Clients extends AddClient<'js', 'ofetch'> {
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* js/ofetch
|
|
8
|
+
*/
|
|
2
9
|
export declare function ofetch(request?: Partial<Request>): Source;
|
|
3
10
|
//# sourceMappingURL=ofetch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ofetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/js/ofetch/ofetch.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,MAAM,EAGZ,MAAM,eAAe,CAAA;AAEtB,wBAAgB,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"ofetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/js/ofetch/ofetch.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,OAAO,EACZ,KAAK,MAAM,EAGZ,MAAM,eAAe,CAAA;AAEtB,OAAO,CAAC,MAAM,CAAC;IAEb,UAAU,OAAQ,SAAQ,SAAS,CAAC,IAAI,EAAE,QAAQ,CAAC;KAAG;CACvD;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,MAAM,CAmFzD"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { arrayToObject } from '../../../core/utils/arrayToObject.js';
|
|
2
2
|
import { objectToString } from '../../../core/utils/objectToString.js';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* js/ofetch
|
|
6
|
+
*/
|
|
4
7
|
function ofetch(request) {
|
|
5
8
|
// Defaults
|
|
6
9
|
const normalizedRequest = {
|
|
@@ -59,7 +62,9 @@ function ofetch(request) {
|
|
|
59
62
|
? `, ${objectToString(options)}`
|
|
60
63
|
: '';
|
|
61
64
|
// Code Template
|
|
62
|
-
const code = `ofetch
|
|
65
|
+
const code = `import { ofetch } from 'ofetch'
|
|
66
|
+
|
|
67
|
+
ofetch('${normalizedRequest.url}'${jsonOptions})`;
|
|
63
68
|
return {
|
|
64
69
|
target: 'js',
|
|
65
70
|
client: 'ofetch',
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
import { type Request, type Source } from '../../../core/index.js';
|
|
1
|
+
import { type AddClient, type Request, type Source } from '../../../core/index.js';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Clients extends AddClient<'node', 'fetch'> {
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* node/fetch
|
|
8
|
+
*/
|
|
2
9
|
export declare function fetch(request?: Partial<Request>): Source;
|
|
3
10
|
//# sourceMappingURL=fetch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/fetch/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,MAAM,EAGZ,MAAM,eAAe,CAAA;AAEtB,wBAAgB,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,MAAM,CA6ExD"}
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/fetch/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,OAAO,EACZ,KAAK,MAAM,EAGZ,MAAM,eAAe,CAAA;AAEtB,OAAO,CAAC,MAAM,CAAC;IAEb,UAAU,OAAQ,SAAQ,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC;KAAG;CACxD;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,MAAM,CA6ExD"}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
import { type Request, type Source } from '../../../core/index.js';
|
|
1
|
+
import { type AddClient, type Request, type Source } from '../../../core/index.js';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Clients extends AddClient<'node', 'ofetch'> {
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* node/ofetch
|
|
8
|
+
*/
|
|
2
9
|
export declare function ofetch(request?: Partial<Request>): Source;
|
|
3
10
|
//# sourceMappingURL=ofetch.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ofetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/ofetch/ofetch.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,MAAM,EAGZ,MAAM,eAAe,CAAA;AAEtB,wBAAgB,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"ofetch.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/ofetch/ofetch.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,OAAO,EACZ,KAAK,MAAM,EAGZ,MAAM,eAAe,CAAA;AAEtB,OAAO,CAAC,MAAM,CAAC;IAEb,UAAU,OAAQ,SAAQ,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC;KAAG;CACzD;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,MAAM,CAmFzD"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { arrayToObject } from '../../../core/utils/arrayToObject.js';
|
|
2
2
|
import { objectToString } from '../../../core/utils/objectToString.js';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* node/ofetch
|
|
6
|
+
*/
|
|
4
7
|
function ofetch(request) {
|
|
5
8
|
// Defaults
|
|
6
9
|
const normalizedRequest = {
|
|
@@ -59,7 +62,9 @@ function ofetch(request) {
|
|
|
59
62
|
? `, ${objectToString(options)}`
|
|
60
63
|
: '';
|
|
61
64
|
// Code Template
|
|
62
|
-
const code = `ofetch
|
|
65
|
+
const code = `import { ofetch } from 'ofetch'
|
|
66
|
+
|
|
67
|
+
ofetch('${normalizedRequest.url}'${jsonOptions})`;
|
|
63
68
|
return {
|
|
64
69
|
target: 'node',
|
|
65
70
|
client: 'ofetch',
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
import { type Request, type Source } from '../../../core/index.js';
|
|
1
|
+
import { type AddClient, type Request, type Source } from '../../../core/index.js';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Clients extends AddClient<'node', 'undici'> {
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* node/undici
|
|
8
|
+
*/
|
|
2
9
|
export declare function undici(request?: Partial<Request>): Source;
|
|
3
10
|
//# sourceMappingURL=undici.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"undici.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/undici/undici.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,MAAM,EAGZ,MAAM,eAAe,CAAA;AAEtB,wBAAgB,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,MAAM,CA+EzD"}
|
|
1
|
+
{"version":3,"file":"undici.d.ts","sourceRoot":"","sources":["../../../../src/plugins/node/undici/undici.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,OAAO,EACZ,KAAK,MAAM,EAGZ,MAAM,eAAe,CAAA;AAEtB,OAAO,CAAC,MAAM,CAAC;IAEb,UAAU,OAAQ,SAAQ,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC;KAAG;CACzD;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,MAAM,CA+EzD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AddClient, PluginConfiguration, Request, Source } from '../../../core/index.js';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Clients extends AddClient<'shell', 'curl'> {
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* shell/curl
|
|
8
|
+
*/
|
|
9
|
+
export declare function curl(request?: Partial<Request>, configuration?: PluginConfiguration): Source;
|
|
10
|
+
//# sourceMappingURL=curl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"curl.d.ts","sourceRoot":"","sources":["../../../../src/plugins/shell/curl/curl.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,mBAAmB,EACnB,OAAO,EACP,MAAM,EACP,MAAM,eAAe,CAAA;AAEtB,OAAO,CAAC,MAAM,CAAC;IAEb,UAAU,OAAQ,SAAQ,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC;KAAG;CACxD;AAED;;GAEG;AACH,wBAAgB,IAAI,CAClB,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,EAC1B,aAAa,CAAC,EAAE,mBAAmB,GAClC,MAAM,CAoHR"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* shell/curl
|
|
3
|
+
*/
|
|
4
|
+
function curl(request, configuration) {
|
|
5
|
+
// Defaults
|
|
6
|
+
const normalizedRequest = {
|
|
7
|
+
method: 'GET',
|
|
8
|
+
...request,
|
|
9
|
+
};
|
|
10
|
+
// Normalization
|
|
11
|
+
normalizedRequest.method = normalizedRequest.method.toUpperCase();
|
|
12
|
+
// Build curl command parts
|
|
13
|
+
const parts = ['curl'];
|
|
14
|
+
// URL (quote if has query parameters or special characters)
|
|
15
|
+
const queryString = normalizedRequest.queryString?.length
|
|
16
|
+
? '?' +
|
|
17
|
+
normalizedRequest.queryString
|
|
18
|
+
.map((param) => {
|
|
19
|
+
// Ensure both name and value are fully URI encoded
|
|
20
|
+
const encodedName = encodeURIComponent(param.name);
|
|
21
|
+
const encodedValue = encodeURIComponent(param.value);
|
|
22
|
+
return `${encodedName}=${encodedValue}`;
|
|
23
|
+
})
|
|
24
|
+
.join('&')
|
|
25
|
+
: '';
|
|
26
|
+
const url = `${normalizedRequest.url}${queryString}`;
|
|
27
|
+
const hasSpecialChars = /[\s<>[\]{}|\\^%]/.test(url);
|
|
28
|
+
const urlPart = queryString || hasSpecialChars ? `'${url}'` : url;
|
|
29
|
+
parts[0] = `curl ${urlPart}`;
|
|
30
|
+
// Method
|
|
31
|
+
if (normalizedRequest.method !== 'GET') {
|
|
32
|
+
parts.push(`--request ${normalizedRequest.method}`);
|
|
33
|
+
}
|
|
34
|
+
// Basic Auth
|
|
35
|
+
if (configuration?.auth?.username && configuration?.auth?.password) {
|
|
36
|
+
parts.push(`--user '${configuration.auth.username}:${configuration.auth.password}'`);
|
|
37
|
+
}
|
|
38
|
+
// Headers
|
|
39
|
+
if (normalizedRequest.headers?.length) {
|
|
40
|
+
normalizedRequest.headers.forEach((header) => {
|
|
41
|
+
parts.push(`--header '${header.name}: ${header.value}'`);
|
|
42
|
+
});
|
|
43
|
+
// Add compressed flag if Accept-Encoding header includes compression
|
|
44
|
+
const acceptEncoding = normalizedRequest.headers.find((header) => header.name.toLowerCase() === 'accept-encoding');
|
|
45
|
+
if (acceptEncoding && /gzip|deflate/.test(acceptEncoding.value)) {
|
|
46
|
+
parts.push('--compressed');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// Cookies
|
|
50
|
+
if (normalizedRequest.cookies?.length) {
|
|
51
|
+
const cookieString = normalizedRequest.cookies
|
|
52
|
+
.map((cookie) => {
|
|
53
|
+
// Encode both cookie name and value to handle special characters
|
|
54
|
+
const encodedName = encodeURIComponent(cookie.name);
|
|
55
|
+
const encodedValue = encodeURIComponent(cookie.value);
|
|
56
|
+
return `${encodedName}=${encodedValue}`;
|
|
57
|
+
})
|
|
58
|
+
.join('; ');
|
|
59
|
+
parts.push(`--cookie '${cookieString}'`);
|
|
60
|
+
}
|
|
61
|
+
// Body
|
|
62
|
+
if (normalizedRequest.postData) {
|
|
63
|
+
if (normalizedRequest.postData.mimeType === 'application/json') {
|
|
64
|
+
// Pretty print JSON data
|
|
65
|
+
if (normalizedRequest.postData.text) {
|
|
66
|
+
const jsonData = JSON.parse(normalizedRequest.postData.text);
|
|
67
|
+
const prettyJson = JSON.stringify(jsonData, null, 2);
|
|
68
|
+
parts.push(`--data '${prettyJson}'`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else if (normalizedRequest.postData.mimeType === 'application/octet-stream') {
|
|
72
|
+
parts.push(`--data-binary '${normalizedRequest.postData.text}'`);
|
|
73
|
+
}
|
|
74
|
+
else if (normalizedRequest.postData.mimeType ===
|
|
75
|
+
'application/x-www-form-urlencoded' &&
|
|
76
|
+
normalizedRequest.postData.params) {
|
|
77
|
+
// Handle URL-encoded form data
|
|
78
|
+
normalizedRequest.postData.params.forEach((param) => {
|
|
79
|
+
parts.push(`--data-urlencode '${encodeURIComponent(param.name)}=${param.value}'`);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
else if (normalizedRequest.postData.mimeType === 'multipart/form-data' &&
|
|
83
|
+
normalizedRequest.postData.params) {
|
|
84
|
+
// Handle multipart form data
|
|
85
|
+
normalizedRequest.postData.params.forEach((param) => {
|
|
86
|
+
if (param.fileName !== undefined) {
|
|
87
|
+
parts.push(`--form '${param.name}=@${param.fileName}'`);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
parts.push(`--form '${param.name}=${param.value}'`);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
parts.push(`--data "${normalizedRequest.postData.text}"`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
target: 'shell',
|
|
100
|
+
client: 'curl',
|
|
101
|
+
code: parts.join(' \\\n '),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export { curl };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/plugins/shell/curl/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { curl } from './curl.js';
|
package/dist/snippetz.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import type { ClientId, Request, TargetId } from './core/index.js';
|
|
2
|
-
import {
|
|
2
|
+
import { curl } from './plugins/shell/curl/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Generate code examples for HAR requests
|
|
5
5
|
*/
|
|
6
6
|
export declare function snippetz(): {
|
|
7
|
-
get(target: TargetId, client: ClientId
|
|
7
|
+
get(target: TargetId, client: ClientId<TargetId>, request: Partial<Request>): import("./core/index.js").Source | {
|
|
8
8
|
code: string;
|
|
9
9
|
};
|
|
10
|
-
print(target:
|
|
11
|
-
targets():
|
|
12
|
-
clients(): ClientId[];
|
|
10
|
+
print<T extends TargetId>(target: T, client: ClientId<T>, request: Partial<Request>): string;
|
|
11
|
+
targets(): ("js" | "node" | "shell")[];
|
|
12
|
+
clients(): ClientId<"js" | "node" | "shell">[];
|
|
13
13
|
plugins(): {
|
|
14
|
-
target:
|
|
15
|
-
client: ClientId
|
|
14
|
+
target: "js" | "node" | "shell";
|
|
15
|
+
client: ClientId<"js" | "node" | "shell">;
|
|
16
16
|
}[];
|
|
17
|
-
findPlugin(target:
|
|
18
|
-
hasPlugin(target: string, client: string): boolean;
|
|
17
|
+
findPlugin<T extends TargetId>(target: T | string, client: ClientId<T> | string): typeof curl | undefined;
|
|
18
|
+
hasPlugin<T extends TargetId>(target: T | string, client: ClientId<T> | string): boolean;
|
|
19
19
|
};
|
|
20
20
|
//# sourceMappingURL=snippetz.d.ts.map
|
package/dist/snippetz.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snippetz.d.ts","sourceRoot":"","sources":["../src/snippetz.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"snippetz.d.ts","sourceRoot":"","sources":["../src/snippetz.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAMzD,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AAE3C;;GAEG;AACH,wBAAgB,QAAQ;gBAKV,QAAQ,UACR,QAAQ,CAAC,QAAQ,CAAC,WACjB,OAAO,CAAC,OAAO,CAAC;;;UAYrB,CAAC,SAAS,QAAQ,UACd,CAAC,UACD,QAAQ,CAAC,CAAC,CAAC,WACV,OAAO,CAAC,OAAO,CAAC;;;;;;;eA0BhB,CAAC,SAAS,QAAQ,UACnB,CAAC,GAAG,MAAM,UACV,QAAQ,CAAC,CAAC,CAAC,GAAG,MAAM;cAQpB,CAAC,SAAS,QAAQ,UAClB,CAAC,GAAG,MAAM,UACV,QAAQ,CAAC,CAAC,CAAC,GAAG,MAAM;EAKjC"}
|
package/dist/snippetz.js
CHANGED
|
@@ -3,12 +3,13 @@ import { fetch } from './plugins/node/fetch/fetch.js';
|
|
|
3
3
|
import { fetch as fetch$1 } from './plugins/js/fetch/fetch.js';
|
|
4
4
|
import { ofetch } from './plugins/js/ofetch/ofetch.js';
|
|
5
5
|
import { ofetch as ofetch$1 } from './plugins/node/ofetch/ofetch.js';
|
|
6
|
+
import { curl } from './plugins/shell/curl/curl.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Generate code examples for HAR requests
|
|
9
10
|
*/
|
|
10
11
|
function snippetz() {
|
|
11
|
-
const plugins = [undici, fetch, fetch$1, ofetch, ofetch$1];
|
|
12
|
+
const plugins = [undici, fetch, fetch$1, ofetch, ofetch$1, curl];
|
|
12
13
|
return {
|
|
13
14
|
get(target, client, request) {
|
|
14
15
|
const plugin = this.findPlugin(target, client);
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"url": "https://github.com/scalar/scalar.git",
|
|
10
10
|
"directory": "packages/snippetz"
|
|
11
11
|
},
|
|
12
|
-
"version": "0.2.
|
|
12
|
+
"version": "0.2.5",
|
|
13
13
|
"engines": {
|
|
14
14
|
"node": ">=18"
|
|
15
15
|
},
|
|
@@ -18,31 +18,43 @@
|
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
20
|
"import": "./dist/index.js",
|
|
21
|
-
"types": "./dist/index.d.ts"
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./plugins/shell/curl": {
|
|
25
|
+
"import": "./dist/plugins/shell/curl/index.js",
|
|
26
|
+
"types": "./dist/plugins/shell/curl/index.d.ts",
|
|
27
|
+
"default": "./dist/plugins/shell/curl/index.js"
|
|
22
28
|
},
|
|
23
29
|
"./plugins/node/undici": {
|
|
24
30
|
"import": "./dist/plugins/node/undici/index.js",
|
|
25
|
-
"types": "./dist/plugins/node/undici/index.d.ts"
|
|
31
|
+
"types": "./dist/plugins/node/undici/index.d.ts",
|
|
32
|
+
"default": "./dist/plugins/node/undici/index.js"
|
|
26
33
|
},
|
|
27
34
|
"./plugins/node/ofetch": {
|
|
28
35
|
"import": "./dist/plugins/node/ofetch/index.js",
|
|
29
|
-
"types": "./dist/plugins/node/ofetch/index.d.ts"
|
|
36
|
+
"types": "./dist/plugins/node/ofetch/index.d.ts",
|
|
37
|
+
"default": "./dist/plugins/node/ofetch/index.js"
|
|
30
38
|
},
|
|
31
39
|
"./plugins/node/fetch": {
|
|
32
40
|
"import": "./dist/plugins/node/fetch/index.js",
|
|
33
|
-
"types": "./dist/plugins/node/fetch/index.d.ts"
|
|
41
|
+
"types": "./dist/plugins/node/fetch/index.d.ts",
|
|
42
|
+
"default": "./dist/plugins/node/fetch/index.js"
|
|
34
43
|
},
|
|
35
44
|
"./plugins/js/ofetch": {
|
|
36
45
|
"import": "./dist/plugins/js/ofetch/index.js",
|
|
37
|
-
"types": "./dist/plugins/js/ofetch/index.d.ts"
|
|
46
|
+
"types": "./dist/plugins/js/ofetch/index.d.ts",
|
|
47
|
+
"default": "./dist/plugins/js/ofetch/index.js"
|
|
38
48
|
},
|
|
39
49
|
"./plugins/js/fetch": {
|
|
40
50
|
"import": "./dist/plugins/js/fetch/index.js",
|
|
41
|
-
"types": "./dist/plugins/js/fetch/index.d.ts"
|
|
51
|
+
"types": "./dist/plugins/js/fetch/index.d.ts",
|
|
52
|
+
"default": "./dist/plugins/js/fetch/index.js"
|
|
42
53
|
},
|
|
43
54
|
"./core": {
|
|
44
55
|
"import": "./dist/core/index.js",
|
|
45
|
-
"types": "./dist/core/index.d.ts"
|
|
56
|
+
"types": "./dist/core/index.d.ts",
|
|
57
|
+
"default": "./dist/core/index.js"
|
|
46
58
|
}
|
|
47
59
|
},
|
|
48
60
|
"files": [
|
|
@@ -52,10 +64,14 @@
|
|
|
52
64
|
"module": "./dist/index.js",
|
|
53
65
|
"devDependencies": {
|
|
54
66
|
"@types/har-format": "^1.2.15",
|
|
55
|
-
"@scalar/build-tooling": "0.1.
|
|
67
|
+
"@scalar/build-tooling": "0.1.12"
|
|
56
68
|
},
|
|
57
69
|
"scripts": {
|
|
58
70
|
"build": "scalar-build-rollup",
|
|
71
|
+
"build:playground": "cd ./playground && pnpm build",
|
|
72
|
+
"dev": "cd ./playground && pnpm dev",
|
|
73
|
+
"lint:check": "eslint .",
|
|
74
|
+
"lint:fix": "eslint . --fix",
|
|
59
75
|
"test": "vitest",
|
|
60
76
|
"types:build": "scalar-types-build",
|
|
61
77
|
"types:check": "scalar-types-check"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isKeyNeedsQuotes.d.ts","sourceRoot":"","sources":["../../../src/core/utils/isKeyNeedsQuotes.ts"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,WAE3C"}
|