@scalar/snippetz 0.2.4 → 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.
Files changed (44) hide show
  1. package/dist/core/index.d.ts +1 -1
  2. package/dist/core/index.d.ts.map +1 -1
  3. package/dist/core/index.js +1 -1
  4. package/dist/core/types.d.ts +21 -3
  5. package/dist/core/types.d.ts.map +1 -1
  6. package/dist/core/types.test-d.d.ts +2 -0
  7. package/dist/core/types.test-d.d.ts.map +1 -0
  8. package/dist/core/utils/arrayToObject.d.ts +6 -1
  9. package/dist/core/utils/arrayToObject.d.ts.map +1 -1
  10. package/dist/core/utils/arrayToObject.js +6 -1
  11. package/dist/core/utils/needsQuotes.d.ts +7 -0
  12. package/dist/core/utils/needsQuotes.d.ts.map +1 -0
  13. package/dist/core/utils/needsQuotes.js +10 -0
  14. package/dist/core/utils/objectToString.d.ts +5 -0
  15. package/dist/core/utils/objectToString.d.ts.map +1 -1
  16. package/dist/core/utils/objectToString.js +7 -2
  17. package/dist/plugins/js/fetch/fetch.d.ts +8 -1
  18. package/dist/plugins/js/fetch/fetch.d.ts.map +1 -1
  19. package/dist/plugins/js/fetch/fetch.js +3 -0
  20. package/dist/plugins/js/ofetch/ofetch.d.ts +8 -1
  21. package/dist/plugins/js/ofetch/ofetch.d.ts.map +1 -1
  22. package/dist/plugins/js/ofetch/ofetch.js +6 -1
  23. package/dist/plugins/node/fetch/fetch.d.ts +8 -1
  24. package/dist/plugins/node/fetch/fetch.d.ts.map +1 -1
  25. package/dist/plugins/node/fetch/fetch.js +3 -0
  26. package/dist/plugins/node/ofetch/ofetch.d.ts +8 -1
  27. package/dist/plugins/node/ofetch/ofetch.d.ts.map +1 -1
  28. package/dist/plugins/node/ofetch/ofetch.js +6 -1
  29. package/dist/plugins/node/undici/undici.d.ts +8 -1
  30. package/dist/plugins/node/undici/undici.d.ts.map +1 -1
  31. package/dist/plugins/node/undici/undici.js +3 -0
  32. package/dist/plugins/shell/curl/curl.d.ts +10 -0
  33. package/dist/plugins/shell/curl/curl.d.ts.map +1 -0
  34. package/dist/plugins/shell/curl/curl.js +105 -0
  35. package/dist/plugins/shell/curl/index.d.ts +2 -0
  36. package/dist/plugins/shell/curl/index.d.ts.map +1 -0
  37. package/dist/plugins/shell/curl/index.js +1 -0
  38. package/dist/snippetz.d.ts +9 -9
  39. package/dist/snippetz.d.ts.map +1 -1
  40. package/dist/snippetz.js +2 -1
  41. package/package.json +7 -2
  42. package/dist/core/utils/isKeyNeedsQuotes.d.ts +0 -2
  43. package/dist/core/utils/isKeyNeedsQuotes.d.ts.map +0 -1
  44. package/dist/core/utils/isKeyNeedsQuotes.js +0 -5
@@ -1,5 +1,5 @@
1
1
  export * from './utils/arrayToObject.js';
2
- export * from './utils/isKeyNeedsQuotes.js';
2
+ export * from './utils/needsQuotes.js';
3
3
  export * from './utils/objectToString.js';
4
4
  export * from './types';
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,0BAA0B,CAAA;AACxC,cAAc,wBAAwB,CAAA;AAEtC,cAAc,SAAS,CAAA"}
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"}
@@ -1,3 +1,3 @@
1
1
  export { arrayToObject } from './utils/arrayToObject.js';
2
- export { isKeyNeedsQuotes } from './utils/isKeyNeedsQuotes.js';
2
+ export { needsQuotes } from './utils/needsQuotes.js';
3
3
  export { objectToString } from './utils/objectToString.js';
@@ -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
- export type TargetId = 'node' | 'js';
11
- export type ClientId = 'undici' | 'fetch' | 'ofetch';
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
@@ -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;IAChB,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,IAAI,CAAA;AAEpC,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.test-d.d.ts.map
@@ -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
- /** Helper function to map { name: 'foo', value: 'bar' } to { foo: 'bar' } */
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,6EAA6E;AAC7E,wBAAgB,aAAa,CAAC,KAAK,EAAE,GAAG,OAKvC"}
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
- /** Helper function to map { name: 'foo', value: 'bar' } to { foo: 'bar' } */
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,7 @@
1
+ /**
2
+ * Checks if a key needs to be wrapped in quotes when used as an object property
3
+ *
4
+ * Returns true if the key contains spaces or hyphens
5
+ */
6
+ export declare function needsQuotes(key: string): boolean;
7
+ //# sourceMappingURL=needsQuotes.d.ts.map
@@ -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"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Checks if a key needs to be wrapped in quotes when used as an object property
3
+ *
4
+ * Returns true if the key contains spaces or hyphens
5
+ */
6
+ function needsQuotes(key) {
7
+ return /\s|-/.test(key);
8
+ }
9
+
10
+ export { needsQuotes };
@@ -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 { isKeyNeedsQuotes } from './isKeyNeedsQuotes.js';
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 = isKeyNeedsQuotes(key) ? `'${key}'` : key;
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,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/fetch
6
+ */
4
7
  function fetch(request) {
5
8
  // Defaults
6
9
  const normalizedRequest = {
@@ -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,CAiFzD"}
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('${normalizedRequest.url}'${jsonOptions})`;
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,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/fetch
6
+ */
4
7
  function fetch(request) {
5
8
  // Defaults
6
9
  const normalizedRequest = {
@@ -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,CAiFzD"}
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('${normalizedRequest.url}'${jsonOptions})`;
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"}
@@ -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/undici
6
+ */
4
7
  function undici(request) {
5
8
  // Defaults
6
9
  const normalizedRequest = {
@@ -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,2 @@
1
+ export * from './curl.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -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';
@@ -1,20 +1,20 @@
1
1
  import type { ClientId, Request, TargetId } from './core/index.js';
2
- import { undici } from './plugins/node/undici/index.js';
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, request: Partial<Request>): import("./core/index.js").Source | {
7
+ get(target: TargetId, client: ClientId<TargetId>, request: Partial<Request>): import("./core/index.js").Source | {
8
8
  code: string;
9
9
  };
10
- print(target: TargetId, client: ClientId, request: Partial<Request>): string;
11
- targets(): TargetId[];
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: TargetId;
15
- client: ClientId;
14
+ target: "js" | "node" | "shell";
15
+ client: ClientId<"js" | "node" | "shell">;
16
16
  }[];
17
- findPlugin(target: TargetId, client: ClientId): typeof undici | undefined;
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
@@ -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;AAKzD,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAE9C;;GAEG;AACH,wBAAgB,QAAQ;gBAIR,QAAQ,UAAU,QAAQ,WAAW,OAAO,CAAC,OAAO,CAAC;;;kBAWnD,QAAQ,UAAU,QAAQ,WAAW,OAAO,CAAC,OAAO,CAAC;;;;;;;uBAyBhD,QAAQ,UAAU,QAAQ;sBAO3B,MAAM,UAAU,MAAM;EAI3C"}
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.4",
12
+ "version": "0.2.5",
13
13
  "engines": {
14
14
  "node": ">=18"
15
15
  },
@@ -21,6 +21,11 @@
21
21
  "types": "./dist/index.d.ts",
22
22
  "default": "./dist/index.js"
23
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"
28
+ },
24
29
  "./plugins/node/undici": {
25
30
  "import": "./dist/plugins/node/undici/index.js",
26
31
  "types": "./dist/plugins/node/undici/index.d.ts",
@@ -59,7 +64,7 @@
59
64
  "module": "./dist/index.js",
60
65
  "devDependencies": {
61
66
  "@types/har-format": "^1.2.15",
62
- "@scalar/build-tooling": "0.1.11"
67
+ "@scalar/build-tooling": "0.1.12"
63
68
  },
64
69
  "scripts": {
65
70
  "build": "scalar-build-rollup",
@@ -1,2 +0,0 @@
1
- export declare function isKeyNeedsQuotes(key: string): boolean;
2
- //# sourceMappingURL=isKeyNeedsQuotes.d.ts.map
@@ -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"}
@@ -1,5 +0,0 @@
1
- function isKeyNeedsQuotes(key) {
2
- return /\s|-/.test(key);
3
- }
4
-
5
- export { isKeyNeedsQuotes };