strapi-typed-client 1.6.1 → 2.0.1
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 -2
- package/dist/cli/commands/check.d.ts +2 -3
- package/dist/cli/commands/check.d.ts.map +1 -1
- package/dist/cli/commands/check.js +3 -3
- package/dist/cli/commands/check.js.map +1 -1
- package/dist/cli/commands/generate.d.ts +3 -3
- package/dist/cli/commands/generate.d.ts.map +1 -1
- package/dist/cli/commands/generate.js +6 -4
- package/dist/cli/commands/generate.js.map +1 -1
- package/dist/cli/commands/watch.d.ts +3 -3
- package/dist/cli/commands/watch.d.ts.map +1 -1
- package/dist/cli/commands/watch.js +19 -9
- package/dist/cli/commands/watch.js.map +1 -1
- package/dist/cli/utils/file-writer.d.ts +8 -7
- package/dist/cli/utils/file-writer.d.ts.map +1 -1
- package/dist/cli/utils/file-writer.js +17 -61
- package/dist/cli/utils/file-writer.js.map +1 -1
- package/dist/core/endpoint-converter.d.ts +5 -1
- package/dist/core/endpoint-converter.d.ts.map +1 -1
- package/dist/core/endpoint-converter.js +114 -8
- package/dist/core/endpoint-converter.js.map +1 -1
- package/dist/generator/auth-api-generator.d.ts +11 -3
- package/dist/generator/auth-api-generator.d.ts.map +1 -1
- package/dist/generator/auth-api-generator.js +213 -220
- package/dist/generator/auth-api-generator.js.map +1 -1
- package/dist/generator/client-generator.d.ts +9 -0
- package/dist/generator/client-generator.d.ts.map +1 -1
- package/dist/generator/client-generator.js +201 -78
- package/dist/generator/client-generator.js.map +1 -1
- package/dist/generator/custom-api-generator.d.ts +1 -1
- package/dist/generator/custom-api-generator.d.ts.map +1 -1
- package/dist/generator/custom-api-generator.js +29 -5
- package/dist/generator/custom-api-generator.js.map +1 -1
- package/dist/generator/index-generator.d.ts.map +1 -1
- package/dist/generator/index-generator.js +0 -1
- package/dist/generator/index-generator.js.map +1 -1
- package/dist/generator/index.d.ts +18 -1
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/index.js +85 -9
- package/dist/generator/index.js.map +1 -1
- package/dist/generator/plugin-api-generator.d.ts +2 -0
- package/dist/generator/plugin-api-generator.d.ts.map +1 -1
- package/dist/generator/plugin-api-generator.js +23 -1
- package/dist/generator/plugin-api-generator.js.map +1 -1
- package/dist/generator/plugin-registry.d.ts +5 -0
- package/dist/generator/plugin-registry.d.ts.map +1 -1
- package/dist/generator/plugin-registry.js +2 -1
- package/dist/generator/plugin-registry.js.map +1 -1
- package/dist/generator/types-generator.d.ts +13 -3
- package/dist/generator/types-generator.d.ts.map +1 -1
- package/dist/generator/types-generator.js +91 -101
- package/dist/generator/types-generator.js.map +1 -1
- package/dist/next/index.d.ts +9 -1
- package/dist/next/index.d.ts.map +1 -1
- package/dist/next/index.js +46 -45
- package/dist/next/index.js.map +1 -1
- package/dist/schema-types.d.ts +1 -1
- package/dist/schema-types.d.ts.map +1 -1
- package/dist/shared/client-header.d.ts +19 -0
- package/dist/shared/client-header.d.ts.map +1 -0
- package/dist/shared/client-header.js +58 -0
- package/dist/shared/client-header.js.map +1 -0
- package/package.json +9 -15
- package/dist/index.d.ts +0 -102
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -79
- package/dist/index.js.map +0 -1
- package/src/generator/templates/stringify-query.ts +0 -36
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read a constant baked into the generated client header — SCHEMA_HASH and
|
|
3
|
+
* GENERATOR_VERSION are emitted as the first exports of client.ts/client.js, so
|
|
4
|
+
* reading the file head is enough and avoids parsing the whole client.
|
|
5
|
+
*
|
|
6
|
+
* Node-only (uses `fs`). Shared by the CLI file-writer and the Next.js plugin
|
|
7
|
+
* so the two readers can't drift. Do NOT re-export from the shared barrel —
|
|
8
|
+
* keep `fs` out of any browser bundle (same rule as `shared/version`).
|
|
9
|
+
*
|
|
10
|
+
* @module shared/client-header
|
|
11
|
+
*/
|
|
12
|
+
import * as fs from 'fs';
|
|
13
|
+
import * as path from 'path';
|
|
14
|
+
const HEADER_HEAD_BYTES = 512;
|
|
15
|
+
/**
|
|
16
|
+
* Read the first N bytes of a file without loading the whole thing.
|
|
17
|
+
*/
|
|
18
|
+
function readFileHead(filePath, bytes) {
|
|
19
|
+
let fd;
|
|
20
|
+
try {
|
|
21
|
+
fd = fs.openSync(filePath, 'r');
|
|
22
|
+
const buf = Buffer.alloc(bytes);
|
|
23
|
+
const read = fs.readSync(fd, buf, 0, bytes, 0);
|
|
24
|
+
return buf.subarray(0, read).toString('utf-8');
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
finally {
|
|
30
|
+
if (fd !== undefined) {
|
|
31
|
+
try {
|
|
32
|
+
fs.closeSync(fd);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
/* ignore */
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Read a `export const <NAME> = '<value>'` baked into the generated client
|
|
42
|
+
* header. Tries client.ts (raw, .ts mode) first, then client.js (compiled, .js
|
|
43
|
+
* mode). Returns null when not generated or the constant is absent (e.g. a
|
|
44
|
+
* client produced before that constant was stamped).
|
|
45
|
+
*/
|
|
46
|
+
export function readClientHeaderConst(outputDir, name) {
|
|
47
|
+
const re = new RegExp(`${name}\\s*=\\s*['"]([^'"]*)['"]`);
|
|
48
|
+
for (const file of ['client.ts', 'client.js']) {
|
|
49
|
+
const head = readFileHead(path.join(outputDir, file), HEADER_HEAD_BYTES);
|
|
50
|
+
if (!head)
|
|
51
|
+
continue;
|
|
52
|
+
const match = head.match(re);
|
|
53
|
+
if (match)
|
|
54
|
+
return match[1];
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=client-header.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-header.js","sourceRoot":"","sources":["../../src/shared/client-header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CAAC,IAAI;YAAE,SAAQ;QACnB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAC5B,IAAI,KAAK;YAAE,OAAO,KAAK,CAAC,CAAC,CAAC,CAAA;IAC9B,CAAC;IACD,OAAO,IAAI,CAAA;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "strapi-typed-client",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Type-safe Strapi v5 client with automatic TypeScript codegen and populate type inference",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
6
|
"bin": {
|
|
9
7
|
"strapi-types": "./dist/cli/index.js"
|
|
10
8
|
},
|
|
11
9
|
"files": [
|
|
12
10
|
"dist",
|
|
13
|
-
"src/generator/templates/**/*.ts",
|
|
14
11
|
"strapi-server.js",
|
|
15
12
|
"strapi-admin.js"
|
|
16
13
|
],
|
|
@@ -42,11 +39,6 @@
|
|
|
42
39
|
]
|
|
43
40
|
},
|
|
44
41
|
"exports": {
|
|
45
|
-
".": {
|
|
46
|
-
"types": "./dist/index.d.ts",
|
|
47
|
-
"import": "./dist/index.js",
|
|
48
|
-
"default": "./dist/index.js"
|
|
49
|
-
},
|
|
50
42
|
"./plugin": {
|
|
51
43
|
"types": "./dist/plugin/index.d.ts",
|
|
52
44
|
"import": "./dist/plugin/index.js",
|
|
@@ -111,14 +103,12 @@
|
|
|
111
103
|
"@strapi/design-system": "^2.0.0",
|
|
112
104
|
"@strapi/icons": "^2.0.0",
|
|
113
105
|
"@types/node": "^25.6.0",
|
|
114
|
-
"@types/qs": "^6.14.0",
|
|
115
106
|
"@types/react": "^18.0.0",
|
|
116
107
|
"@types/react-dom": "^18.0.0",
|
|
117
108
|
"eslint": "^10.0.0",
|
|
118
109
|
"husky": "^9.1.7",
|
|
119
110
|
"lint-staged": "^16.2.7",
|
|
120
111
|
"prettier": "^3.0.0",
|
|
121
|
-
"qs": "^6.14.2",
|
|
122
112
|
"react": "^18.0.0",
|
|
123
113
|
"react-dom": "^18.0.0",
|
|
124
114
|
"styled-components": "^6.0.0",
|
|
@@ -127,7 +117,7 @@
|
|
|
127
117
|
"typescript-eslint": "^8.55.0",
|
|
128
118
|
"vitepress": "^1.6.4",
|
|
129
119
|
"vitepress-plugin-llms": "^1.11.0",
|
|
130
|
-
"vitest": "^
|
|
120
|
+
"vitest": "^4.1.9"
|
|
131
121
|
},
|
|
132
122
|
"peerDependencies": {
|
|
133
123
|
"@strapi/design-system": "^2.0.0",
|
|
@@ -150,14 +140,18 @@
|
|
|
150
140
|
}
|
|
151
141
|
},
|
|
152
142
|
"engines": {
|
|
153
|
-
"node": ">=
|
|
143
|
+
"node": ">=22.0.0"
|
|
154
144
|
},
|
|
155
145
|
"resolutions": {
|
|
156
|
-
"
|
|
146
|
+
"brace-expansion": ">=5.0.6",
|
|
147
|
+
"esbuild": ">=0.28.1",
|
|
157
148
|
"flatted": ">=3.4.2",
|
|
158
149
|
"lodash": ">=4.17.23",
|
|
159
150
|
"minimatch": ">=10.2.3",
|
|
160
|
-
"
|
|
151
|
+
"picomatch": ">=4.0.4",
|
|
152
|
+
"postcss": ">=8.5.10",
|
|
153
|
+
"rollup": ">=4.59.0",
|
|
154
|
+
"vite": ">=7.3.2"
|
|
161
155
|
},
|
|
162
156
|
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
163
157
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A single validation issue inside a `ValidationError`.
|
|
3
|
-
* Mirrors the Yup-style errors Strapi propagates from schema validation.
|
|
4
|
-
*/
|
|
5
|
-
export interface StrapiValidationIssue {
|
|
6
|
-
path: string[];
|
|
7
|
-
message: string;
|
|
8
|
-
name: string;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Known Strapi v5 error names. Other strings still pass through at
|
|
12
|
-
* runtime (for plugin or future-version errors) via the `(string & {})`
|
|
13
|
-
* fallback.
|
|
14
|
-
*/
|
|
15
|
-
export type StrapiErrorName = 'ValidationError' | 'BadRequestError' | 'PaginationError' | 'UnauthorizedError' | 'ForbiddenError' | 'PolicyError' | 'NotFoundError' | 'ConflictError' | 'PayloadTooLargeError' | 'RateLimitError' | 'ApplicationError' | (string & {});
|
|
16
|
-
/**
|
|
17
|
-
* Maps each known `StrapiErrorName` to its `details` payload shape.
|
|
18
|
-
* Used by `isStrapiErrorOf` to narrow `details` after the discriminator
|
|
19
|
-
* check. Wrapped in `Partial` because Strapi may omit `details` even
|
|
20
|
-
* when the error name is known.
|
|
21
|
-
*/
|
|
22
|
-
export type StrapiErrorDetailsMap = Partial<{
|
|
23
|
-
ValidationError: {
|
|
24
|
-
errors: StrapiValidationIssue[];
|
|
25
|
-
};
|
|
26
|
-
BadRequestError: Record<string, unknown>;
|
|
27
|
-
PaginationError: Record<string, unknown>;
|
|
28
|
-
UnauthorizedError: undefined;
|
|
29
|
-
ForbiddenError: undefined;
|
|
30
|
-
PolicyError: {
|
|
31
|
-
policy?: string;
|
|
32
|
-
message?: string;
|
|
33
|
-
};
|
|
34
|
-
NotFoundError: undefined;
|
|
35
|
-
ConflictError: Record<string, unknown>;
|
|
36
|
-
PayloadTooLargeError: undefined;
|
|
37
|
-
RateLimitError: Record<string, unknown>;
|
|
38
|
-
ApplicationError: Record<string, unknown>;
|
|
39
|
-
}>;
|
|
40
|
-
/**
|
|
41
|
-
* Fallback shape when `errorName` is not in `StrapiErrorDetailsMap`
|
|
42
|
-
* (e.g. 3rd-party plugin errors or Strapi versions newer than this client).
|
|
43
|
-
*/
|
|
44
|
-
export interface UnknownStrapiErrorDetails {
|
|
45
|
-
errorName: string;
|
|
46
|
-
details?: Record<string, unknown>;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Error thrown for non-2xx responses from Strapi. Use `isStrapiErrorOf`
|
|
50
|
-
* to narrow `details` to its typed shape.
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* try { await strapi.articles.create({ title: '' }) }
|
|
54
|
-
* catch (e) {
|
|
55
|
-
* if (isStrapiErrorOf(e, 'ValidationError')) {
|
|
56
|
-
* for (const issue of e.details?.errors ?? []) {
|
|
57
|
-
* console.log(issue.path.join('.'), issue.message)
|
|
58
|
-
* }
|
|
59
|
-
* }
|
|
60
|
-
* }
|
|
61
|
-
*/
|
|
62
|
-
export declare class StrapiError extends Error {
|
|
63
|
-
userMessage: string;
|
|
64
|
-
status: number;
|
|
65
|
-
statusText: string;
|
|
66
|
-
/**
|
|
67
|
-
* Strapi-side error name (e.g. "ValidationError"). `Error.name`
|
|
68
|
-
* itself remains "StrapiError" so Sentry/sourcemap contracts are
|
|
69
|
-
* unchanged.
|
|
70
|
-
*/
|
|
71
|
-
errorName: StrapiErrorName;
|
|
72
|
-
/** Narrow via `isStrapiErrorOf` for typed access. */
|
|
73
|
-
details?: unknown;
|
|
74
|
-
constructor(message: string, userMessage: string, status: number, statusText: string, details?: unknown, errorName?: StrapiErrorName);
|
|
75
|
-
}
|
|
76
|
-
export declare class StrapiConnectionError extends Error {
|
|
77
|
-
url: string;
|
|
78
|
-
cause?: Error;
|
|
79
|
-
constructor(message: string, url: string, cause?: Error);
|
|
80
|
-
}
|
|
81
|
-
/** Type guard: is the value a StrapiError instance? */
|
|
82
|
-
export declare function isStrapiError(err: unknown): err is StrapiError;
|
|
83
|
-
/**
|
|
84
|
-
* Type guard that narrows both `errorName` and `details` for a specific
|
|
85
|
-
* Strapi error type.
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
* if (isStrapiErrorOf(err, 'ValidationError')) {
|
|
89
|
-
* err.details?.errors?.[0]?.path // string[] | undefined
|
|
90
|
-
* }
|
|
91
|
-
*/
|
|
92
|
-
export declare function isStrapiErrorOf<N extends keyof StrapiErrorDetailsMap>(err: unknown, name: N): err is StrapiError & {
|
|
93
|
-
errorName: N;
|
|
94
|
-
details: StrapiErrorDetailsMap[N];
|
|
95
|
-
};
|
|
96
|
-
export declare class StrapiClient {
|
|
97
|
-
constructor(_config: {
|
|
98
|
-
baseURL: string;
|
|
99
|
-
token?: string;
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IAClC,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;CACf;AAED;;;;GAIG;AACH,MAAM,MAAM,eAAe,GACrB,iBAAiB,GACjB,iBAAiB,GACjB,iBAAiB,GACjB,mBAAmB,GACnB,gBAAgB,GAChB,aAAa,GACb,eAAe,GACf,eAAe,GACf,sBAAsB,GACtB,gBAAgB,GAChB,kBAAkB,GAClB,CAAC,MAAM,GAAG,EAAE,CAAC,CAAA;AAEnB;;;;;GAKG;AACH,MAAM,MAAM,qBAAqB,GAAG,OAAO,CAAC;IACxC,eAAe,EAAE;QAAE,MAAM,EAAE,qBAAqB,EAAE,CAAA;KAAE,CAAA;IACpD,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACxC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACxC,iBAAiB,EAAE,SAAS,CAAA;IAC5B,cAAc,EAAE,SAAS,CAAA;IACzB,WAAW,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,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AG;IACpB,SAAS,EAAE,CAAC,CAAA;IACZ,OAAO,EAAE,qBAAqB,CAAC,CAAC,CAAC,CAAA;CACpC,CAEA;AAED,qBAAa,YAAY;gBACT,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;CAG3D"}
|
package/dist/index.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
// Stub file — compiled to dist/index.js by `tsc`.
|
|
2
|
-
// When the user runs `npx strapi-types generate`, the generator overwrites
|
|
3
|
-
// dist/index.js (and .d.ts) with real, schema-aware code.
|
|
4
|
-
// Until then this stub provides importable symbols that throw at runtime
|
|
5
|
-
// with a helpful message explaining what to do.
|
|
6
|
-
//
|
|
7
|
-
// IMPORTANT: keep this file in lockstep with what the generator emits in
|
|
8
|
-
// `src/generator/client-generator.ts`. Pre-generation imports must compile.
|
|
9
|
-
const NOT_GENERATED_MESSAGE = '[strapi-typed-client] Types have not been generated yet.\n' +
|
|
10
|
-
'Run: npx strapi-types generate --url <your-strapi-url>\n' +
|
|
11
|
-
'Docs: https://github.com/BoxLab-Ltd/strapi-typed-client#quick-start';
|
|
12
|
-
/**
|
|
13
|
-
* Error thrown for non-2xx responses from Strapi. Use `isStrapiErrorOf`
|
|
14
|
-
* to narrow `details` to its typed shape.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* try { await strapi.articles.create({ title: '' }) }
|
|
18
|
-
* catch (e) {
|
|
19
|
-
* if (isStrapiErrorOf(e, 'ValidationError')) {
|
|
20
|
-
* for (const issue of e.details?.errors ?? []) {
|
|
21
|
-
* console.log(issue.path.join('.'), issue.message)
|
|
22
|
-
* }
|
|
23
|
-
* }
|
|
24
|
-
* }
|
|
25
|
-
*/
|
|
26
|
-
export class StrapiError extends Error {
|
|
27
|
-
userMessage;
|
|
28
|
-
status;
|
|
29
|
-
statusText;
|
|
30
|
-
/**
|
|
31
|
-
* Strapi-side error name (e.g. "ValidationError"). `Error.name`
|
|
32
|
-
* itself remains "StrapiError" so Sentry/sourcemap contracts are
|
|
33
|
-
* unchanged.
|
|
34
|
-
*/
|
|
35
|
-
errorName;
|
|
36
|
-
/** Narrow via `isStrapiErrorOf` for typed access. */
|
|
37
|
-
details;
|
|
38
|
-
constructor(message, userMessage, status, statusText, details, errorName = 'UnknownError') {
|
|
39
|
-
super(message);
|
|
40
|
-
this.name = 'StrapiError';
|
|
41
|
-
this.userMessage = userMessage;
|
|
42
|
-
this.status = status;
|
|
43
|
-
this.statusText = statusText;
|
|
44
|
-
this.errorName = errorName;
|
|
45
|
-
this.details = details;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
export class StrapiConnectionError extends Error {
|
|
49
|
-
url;
|
|
50
|
-
cause;
|
|
51
|
-
constructor(message, url, cause) {
|
|
52
|
-
super(message);
|
|
53
|
-
this.name = 'StrapiConnectionError';
|
|
54
|
-
this.url = url;
|
|
55
|
-
this.cause = cause;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
/** Type guard: is the value a StrapiError instance? */
|
|
59
|
-
export function isStrapiError(err) {
|
|
60
|
-
return err instanceof StrapiError;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Type guard that narrows both `errorName` and `details` for a specific
|
|
64
|
-
* Strapi error type.
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* if (isStrapiErrorOf(err, 'ValidationError')) {
|
|
68
|
-
* err.details?.errors?.[0]?.path // string[] | undefined
|
|
69
|
-
* }
|
|
70
|
-
*/
|
|
71
|
-
export function isStrapiErrorOf(err, name) {
|
|
72
|
-
return isStrapiError(err) && err.errorName === name;
|
|
73
|
-
}
|
|
74
|
-
export class StrapiClient {
|
|
75
|
-
constructor(_config) {
|
|
76
|
-
throw new Error(NOT_GENERATED_MESSAGE);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -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AAW,CAAA;AACrC,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAC3B,GAAY,EACZ,IAAO;IAKP,OAAO,aAAa,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,SAAS,KAAK,IAAI,CAAA;AACvD,CAAC;AAED,MAAM,OAAO,YAAY;IACrB,YAAY,OAA4C;QACpD,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;IAC1C,CAAC;CACJ"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
export function stringifyQuery(obj: Record<string, unknown>): string {
|
|
2
|
-
const pairs: string[] = []
|
|
3
|
-
for (const key of Object.keys(obj)) {
|
|
4
|
-
appendEntry(obj[key], key, pairs)
|
|
5
|
-
}
|
|
6
|
-
return pairs.join('&')
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function appendEntry(
|
|
10
|
-
value: unknown,
|
|
11
|
-
prefix: string,
|
|
12
|
-
pairs: string[],
|
|
13
|
-
): void {
|
|
14
|
-
if (value === null || value === undefined) return
|
|
15
|
-
if (Array.isArray(value)) {
|
|
16
|
-
for (let i = 0; i < value.length; i++) {
|
|
17
|
-
appendEntry(value[i], `${prefix}[${i}]`, pairs)
|
|
18
|
-
}
|
|
19
|
-
return
|
|
20
|
-
}
|
|
21
|
-
if (value instanceof Date) {
|
|
22
|
-
pairs.push(`${prefix}=${encodeURIComponent(value.toISOString())}`)
|
|
23
|
-
return
|
|
24
|
-
}
|
|
25
|
-
if (typeof value === 'object') {
|
|
26
|
-
for (const key of Object.keys(value as Record<string, unknown>)) {
|
|
27
|
-
appendEntry(
|
|
28
|
-
(value as Record<string, unknown>)[key],
|
|
29
|
-
`${prefix}[${key}]`,
|
|
30
|
-
pairs,
|
|
31
|
-
)
|
|
32
|
-
}
|
|
33
|
-
return
|
|
34
|
-
}
|
|
35
|
-
pairs.push(`${prefix}=${encodeURIComponent(String(value))}`)
|
|
36
|
-
}
|