@sunshaobei/dsh-codex-auth 0.0.0-stage → 0.4.0
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 +43 -2
- package/cordis.patch.yml +12 -0
- package/lib/client.js +391 -0
- package/lib/index.js +394 -0
- package/lib/vendor/cosmokit.js +325 -0
- package/lib/vendor/schemastery.mjs +596 -0
- package/package.json +54 -4
- package/src/client.ts +416 -0
- package/src/index.ts +397 -0
- package/src/vendor/cosmokit.js +325 -0
- package/src/vendor/schemastery.d.mts +8 -0
- package/src/vendor/schemastery.mjs +596 -0
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
//#region lib/types/misc.js
|
|
2
|
+
/** No-op callback returning `undefined` at runtime and `any` at type level. */
|
|
3
|
+
function noop() {}
|
|
4
|
+
/** Return true when a value is `null` or `undefined`. */
|
|
5
|
+
function isNullable(value) {
|
|
6
|
+
return value === null || value === void 0;
|
|
7
|
+
}
|
|
8
|
+
/** Return true when a value is neither `null` nor `undefined`. */
|
|
9
|
+
function isNonNullable(value) {
|
|
10
|
+
return !isNullable(value);
|
|
11
|
+
}
|
|
12
|
+
/** Return true for non-array object values. */
|
|
13
|
+
function isPlainObject(data) {
|
|
14
|
+
return data && typeof data === "object" && !Array.isArray(data);
|
|
15
|
+
}
|
|
16
|
+
/** Filter object entries and return a new object. */
|
|
17
|
+
function filterKeys(object, filter) {
|
|
18
|
+
return Object.fromEntries(Object.entries(object).filter(([key, value]) => filter(key, value)));
|
|
19
|
+
}
|
|
20
|
+
/** Map object values while preserving the original key set. */
|
|
21
|
+
function mapValues(object, transform) {
|
|
22
|
+
return Object.fromEntries(Object.entries(object).map(([key, value]) => [key, transform(value, key)]));
|
|
23
|
+
}
|
|
24
|
+
/** Pick selected keys from an object, optionally including `undefined` values. */
|
|
25
|
+
function pick(source, keys, forced) {
|
|
26
|
+
if (!keys) return { ...source };
|
|
27
|
+
const result = {};
|
|
28
|
+
for (const key of keys) if (forced || source[key] !== void 0) result[key] = source[key];
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
/** Omit selected keys from a shallow object copy. */
|
|
32
|
+
function omit(source, keys) {
|
|
33
|
+
if (!keys) return { ...source };
|
|
34
|
+
const result = { ...source };
|
|
35
|
+
for (const key of keys) Reflect.deleteProperty(result, key);
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
/** Define a non-enumerable writable property and return the object. */
|
|
39
|
+
function defineProperty(object, key, value) {
|
|
40
|
+
return Object.defineProperty(object, key, {
|
|
41
|
+
writable: true,
|
|
42
|
+
value,
|
|
43
|
+
enumerable: false
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region lib/types/array.js
|
|
48
|
+
/** Return true when every item in `array2` is present in `array1`. */
|
|
49
|
+
function contain(array1, array2) {
|
|
50
|
+
return array2.every((item) => array1.includes(item));
|
|
51
|
+
}
|
|
52
|
+
/** Return items that appear in both arrays. */
|
|
53
|
+
function intersection(array1, array2) {
|
|
54
|
+
return array1.filter((item) => array2.includes(item));
|
|
55
|
+
}
|
|
56
|
+
/** Return items from `array1` that do not appear in `array2`. */
|
|
57
|
+
function difference(array1, array2) {
|
|
58
|
+
return array1.filter((item) => !array2.includes(item));
|
|
59
|
+
}
|
|
60
|
+
/** Return the set-union of two arrays while preserving first occurrence order. */
|
|
61
|
+
function union(array1, array2) {
|
|
62
|
+
return Array.from(new Set([...array1, ...array2]));
|
|
63
|
+
}
|
|
64
|
+
/** Remove duplicate values while preserving first occurrence order. */
|
|
65
|
+
function deduplicate(array) {
|
|
66
|
+
return [...new Set(array)];
|
|
67
|
+
}
|
|
68
|
+
/** Remove one item from an array and report whether it was found. */
|
|
69
|
+
function remove(list, item) {
|
|
70
|
+
const index = list?.indexOf(item);
|
|
71
|
+
if (index >= 0) {
|
|
72
|
+
list.splice(index, 1);
|
|
73
|
+
return true;
|
|
74
|
+
} else return false;
|
|
75
|
+
}
|
|
76
|
+
/** Normalize nullish, scalar, or array input to an array. */
|
|
77
|
+
function makeArray(source) {
|
|
78
|
+
return Array.isArray(source) ? source : isNullable(source) ? [] : [source];
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region lib/types/types.js
|
|
82
|
+
/** Test values using `instanceof` with a `toStringTag` fallback. */
|
|
83
|
+
function is(type, value) {
|
|
84
|
+
if (arguments.length === 1) return (value) => is(type, value);
|
|
85
|
+
return type in globalThis && value instanceof globalThis[type] || Object.prototype.toString.call(value).slice(8, -1) === type;
|
|
86
|
+
}
|
|
87
|
+
function isArrayBufferLike(value) {
|
|
88
|
+
return is("ArrayBuffer", value) || is("SharedArrayBuffer", value);
|
|
89
|
+
}
|
|
90
|
+
function isArrayBufferSource(value) {
|
|
91
|
+
return isArrayBufferLike(value) || ArrayBuffer.isView(value);
|
|
92
|
+
}
|
|
93
|
+
/** Binary source detection and base64/hex conversion helpers. */
|
|
94
|
+
var Binary;
|
|
95
|
+
(function(Binary) {
|
|
96
|
+
Binary.is = isArrayBufferLike;
|
|
97
|
+
Binary.isSource = isArrayBufferSource;
|
|
98
|
+
function fromSource(source) {
|
|
99
|
+
if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
|
|
100
|
+
else return source;
|
|
101
|
+
}
|
|
102
|
+
Binary.fromSource = fromSource;
|
|
103
|
+
function toBase64(source) {
|
|
104
|
+
source = fromSource(source);
|
|
105
|
+
if (typeof Buffer !== "undefined") return Buffer.from(source).toString("base64");
|
|
106
|
+
let binary = "";
|
|
107
|
+
const bytes = new Uint8Array(source);
|
|
108
|
+
for (let i = 0; i < bytes.byteLength; i++) binary += String.fromCharCode(bytes[i]);
|
|
109
|
+
return btoa(binary);
|
|
110
|
+
}
|
|
111
|
+
Binary.toBase64 = toBase64;
|
|
112
|
+
function fromBase64(source) {
|
|
113
|
+
if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "base64"));
|
|
114
|
+
return Uint8Array.from(atob(source), (c) => c.charCodeAt(0));
|
|
115
|
+
}
|
|
116
|
+
Binary.fromBase64 = fromBase64;
|
|
117
|
+
function toHex(source) {
|
|
118
|
+
source = fromSource(source);
|
|
119
|
+
if (typeof Buffer !== "undefined") return Buffer.from(source).toString("hex");
|
|
120
|
+
return Array.from(new Uint8Array(source), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
121
|
+
}
|
|
122
|
+
Binary.toHex = toHex;
|
|
123
|
+
function fromHex(source) {
|
|
124
|
+
if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "hex"));
|
|
125
|
+
const hex = source.length % 2 === 0 ? source : source.slice(0, source.length - 1);
|
|
126
|
+
const buffer = [];
|
|
127
|
+
for (let i = 0; i < hex.length; i += 2) buffer.push(parseInt(`${hex[i]}${hex[i + 1]}`, 16));
|
|
128
|
+
return Uint8Array.from(buffer).buffer;
|
|
129
|
+
}
|
|
130
|
+
Binary.fromHex = fromHex;
|
|
131
|
+
})(Binary || (Binary = {}));
|
|
132
|
+
/** Decode a base64 string into binary data. */
|
|
133
|
+
const base64ToArrayBuffer = Binary.fromBase64;
|
|
134
|
+
/** Encode binary data as base64. */
|
|
135
|
+
const arrayBufferToBase64 = Binary.toBase64;
|
|
136
|
+
/** Decode a hex string into binary data. */
|
|
137
|
+
const hexToArrayBuffer = Binary.fromHex;
|
|
138
|
+
/** Encode binary data as hex. */
|
|
139
|
+
const arrayBufferToHex = Binary.toHex;
|
|
140
|
+
/** Deep-clone common JavaScript values while preserving prototypes and cycles. */
|
|
141
|
+
function clone(source, refs = /* @__PURE__ */ new Map()) {
|
|
142
|
+
if (!source || typeof source !== "object") return source;
|
|
143
|
+
if (is("Date", source)) return new Date(source.valueOf());
|
|
144
|
+
if (is("RegExp", source)) return new RegExp(source.source, source.flags);
|
|
145
|
+
if (isArrayBufferLike(source)) return source.slice(0);
|
|
146
|
+
if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
|
|
147
|
+
const cached = refs.get(source);
|
|
148
|
+
if (cached) return cached;
|
|
149
|
+
if (Array.isArray(source)) {
|
|
150
|
+
const result = [];
|
|
151
|
+
refs.set(source, result);
|
|
152
|
+
source.forEach((value, index) => {
|
|
153
|
+
result[index] = Reflect.apply(clone, null, [value, refs]);
|
|
154
|
+
});
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
157
|
+
const result = Object.create(Object.getPrototypeOf(source));
|
|
158
|
+
refs.set(source, result);
|
|
159
|
+
for (const key of Reflect.ownKeys(source)) {
|
|
160
|
+
const descriptor = { ...Reflect.getOwnPropertyDescriptor(source, key) };
|
|
161
|
+
if ("value" in descriptor) descriptor.value = Reflect.apply(clone, null, [descriptor.value, refs]);
|
|
162
|
+
Reflect.defineProperty(result, key, descriptor);
|
|
163
|
+
}
|
|
164
|
+
return result;
|
|
165
|
+
}
|
|
166
|
+
/** Deeply compare arrays, dates, regexps, buffers, and plain object fields. */
|
|
167
|
+
function deepEqual(a, b, strict) {
|
|
168
|
+
if (a === b) return true;
|
|
169
|
+
if (!strict && isNullable(a) && isNullable(b)) return true;
|
|
170
|
+
if (typeof a !== typeof b) return false;
|
|
171
|
+
if (typeof a !== "object") return false;
|
|
172
|
+
if (!a || !b) return false;
|
|
173
|
+
function check(test, then) {
|
|
174
|
+
return test(a) ? test(b) ? then(a, b) : false : test(b) ? false : void 0;
|
|
175
|
+
}
|
|
176
|
+
return check(Array.isArray, (a, b) => a.length === b.length && a.every((item, index) => deepEqual(item, b[index]))) ?? check(is("Date"), (a, b) => a.valueOf() === b.valueOf()) ?? check(is("RegExp"), (a, b) => a.source === b.source && a.flags === b.flags) ?? check(isArrayBufferLike, (a, b) => {
|
|
177
|
+
if (a.byteLength !== b.byteLength) return false;
|
|
178
|
+
const viewA = new Uint8Array(a);
|
|
179
|
+
const viewB = new Uint8Array(b);
|
|
180
|
+
for (let i = 0; i < viewA.length; i++) if (viewA[i] !== viewB[i]) return false;
|
|
181
|
+
return true;
|
|
182
|
+
}) ?? Object.keys({
|
|
183
|
+
...a,
|
|
184
|
+
...b
|
|
185
|
+
}).every((key) => deepEqual(a[key], b[key], strict));
|
|
186
|
+
}
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region lib/types/string.js
|
|
189
|
+
/** Uppercase the first character of a string. */
|
|
190
|
+
function capitalize(source) {
|
|
191
|
+
return source.charAt(0).toUpperCase() + source.slice(1);
|
|
192
|
+
}
|
|
193
|
+
/** Lowercase the first character of a string. */
|
|
194
|
+
function uncapitalize(source) {
|
|
195
|
+
return source.charAt(0).toLowerCase() + source.slice(1);
|
|
196
|
+
}
|
|
197
|
+
/** Convert dash or underscore delimited text to camelCase. */
|
|
198
|
+
function camelCase(source) {
|
|
199
|
+
return source.replace(/[_-][a-z]/g, (str) => str.slice(1).toUpperCase());
|
|
200
|
+
}
|
|
201
|
+
function tokenize(source, delimiters, delimiter) {
|
|
202
|
+
const output = [];
|
|
203
|
+
let state = 0;
|
|
204
|
+
for (let i = 0; i < source.length; i++) {
|
|
205
|
+
const code = source.charCodeAt(i);
|
|
206
|
+
if (code >= 65 && code <= 90) {
|
|
207
|
+
if (state === 1) {
|
|
208
|
+
const next = source.charCodeAt(i + 1);
|
|
209
|
+
if (next >= 97 && next <= 122) output.push(delimiter);
|
|
210
|
+
output.push(code + 32);
|
|
211
|
+
} else {
|
|
212
|
+
if (state !== 0) output.push(delimiter);
|
|
213
|
+
output.push(code + 32);
|
|
214
|
+
}
|
|
215
|
+
state = 1;
|
|
216
|
+
} else if (code >= 97 && code <= 122) {
|
|
217
|
+
output.push(code);
|
|
218
|
+
state = 2;
|
|
219
|
+
} else if (delimiters.includes(code)) {
|
|
220
|
+
if (state !== 0) output.push(delimiter);
|
|
221
|
+
state = 0;
|
|
222
|
+
} else output.push(code);
|
|
223
|
+
}
|
|
224
|
+
return String.fromCharCode(...output);
|
|
225
|
+
}
|
|
226
|
+
/** Convert text to dash-delimited parameter case. */
|
|
227
|
+
function paramCase(source) {
|
|
228
|
+
return tokenize(source, [45, 95], 45);
|
|
229
|
+
}
|
|
230
|
+
/** Convert text to underscore-delimited snake case. */
|
|
231
|
+
function snakeCase(source) {
|
|
232
|
+
return tokenize(source, [45, 95], 95);
|
|
233
|
+
}
|
|
234
|
+
/** Runtime alias for `camelCase`. */
|
|
235
|
+
const camelize = camelCase;
|
|
236
|
+
/** Runtime alias for `paramCase`. */
|
|
237
|
+
const hyphenate = paramCase;
|
|
238
|
+
/** Format a property key as a JavaScript member access suffix. */
|
|
239
|
+
function formatProperty(key) {
|
|
240
|
+
if (typeof key !== "string") return `[${key.toString()}]`;
|
|
241
|
+
return /^[a-z_$][\w$]*$/i.test(key) ? `.${key}` : `[${JSON.stringify(key)}]`;
|
|
242
|
+
}
|
|
243
|
+
/** Remove one trailing slash from a path string. */
|
|
244
|
+
function trimSlash(source) {
|
|
245
|
+
return source.replace(/\/$/, "");
|
|
246
|
+
}
|
|
247
|
+
/** Ensure a path starts with `/` and has no trailing slash. */
|
|
248
|
+
function sanitize(source) {
|
|
249
|
+
if (!source.startsWith("/")) source = "/" + source;
|
|
250
|
+
return trimSlash(source);
|
|
251
|
+
}
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region lib/types/time.js
|
|
254
|
+
/** Time constants plus parsing and formatting helpers. */
|
|
255
|
+
var Time;
|
|
256
|
+
(function(Time) {
|
|
257
|
+
Time.millisecond = 1;
|
|
258
|
+
Time.second = 1e3;
|
|
259
|
+
Time.minute = Time.second * 60;
|
|
260
|
+
Time.hour = Time.minute * 60;
|
|
261
|
+
Time.day = Time.hour * 24;
|
|
262
|
+
Time.week = Time.day * 7;
|
|
263
|
+
let timezoneOffset = (/* @__PURE__ */ new Date()).getTimezoneOffset();
|
|
264
|
+
function setTimezoneOffset(offset) {
|
|
265
|
+
timezoneOffset = offset;
|
|
266
|
+
}
|
|
267
|
+
Time.setTimezoneOffset = setTimezoneOffset;
|
|
268
|
+
function getTimezoneOffset() {
|
|
269
|
+
return timezoneOffset;
|
|
270
|
+
}
|
|
271
|
+
Time.getTimezoneOffset = getTimezoneOffset;
|
|
272
|
+
function getDateNumber(date = /* @__PURE__ */ new Date(), offset) {
|
|
273
|
+
if (typeof date === "number") date = new Date(date);
|
|
274
|
+
if (offset === void 0) offset = timezoneOffset;
|
|
275
|
+
return Math.floor((date.valueOf() / Time.minute - offset) / 1440);
|
|
276
|
+
}
|
|
277
|
+
Time.getDateNumber = getDateNumber;
|
|
278
|
+
function fromDateNumber(value, offset) {
|
|
279
|
+
const date = new Date(value * Time.day);
|
|
280
|
+
if (offset === void 0) offset = timezoneOffset;
|
|
281
|
+
return new Date(+date + offset * Time.minute);
|
|
282
|
+
}
|
|
283
|
+
Time.fromDateNumber = fromDateNumber;
|
|
284
|
+
const numeric = /\d+(?:\.\d+)?/.source;
|
|
285
|
+
const timeRegExp = new RegExp(`^${[
|
|
286
|
+
"w(?:eek(?:s)?)?",
|
|
287
|
+
"d(?:ay(?:s)?)?",
|
|
288
|
+
"h(?:our(?:s)?)?",
|
|
289
|
+
"m(?:in(?:ute)?(?:s)?)?",
|
|
290
|
+
"s(?:ec(?:ond)?(?:s)?)?"
|
|
291
|
+
].map((unit) => `(${numeric}${unit})?`).join("")}$`);
|
|
292
|
+
function parseTime(source) {
|
|
293
|
+
const capture = timeRegExp.exec(source);
|
|
294
|
+
if (!capture) return 0;
|
|
295
|
+
return (parseFloat(capture[1]) * Time.week || 0) + (parseFloat(capture[2]) * Time.day || 0) + (parseFloat(capture[3]) * Time.hour || 0) + (parseFloat(capture[4]) * Time.minute || 0) + (parseFloat(capture[5]) * Time.second || 0);
|
|
296
|
+
}
|
|
297
|
+
Time.parseTime = parseTime;
|
|
298
|
+
function parseDate(date) {
|
|
299
|
+
const parsed = parseTime(date);
|
|
300
|
+
if (parsed) date = Date.now() + parsed;
|
|
301
|
+
else if (/^\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).toLocaleDateString()}-${date}`;
|
|
302
|
+
else if (/^\d{1,2}-\d{1,2}-\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).getFullYear()}-${date}`;
|
|
303
|
+
return date ? new Date(date) : /* @__PURE__ */ new Date();
|
|
304
|
+
}
|
|
305
|
+
Time.parseDate = parseDate;
|
|
306
|
+
function format(ms) {
|
|
307
|
+
const abs = Math.abs(ms);
|
|
308
|
+
if (abs >= Time.day - Time.hour / 2) return Math.round(ms / Time.day) + "d";
|
|
309
|
+
else if (abs >= Time.hour - Time.minute / 2) return Math.round(ms / Time.hour) + "h";
|
|
310
|
+
else if (abs >= Time.minute - Time.second / 2) return Math.round(ms / Time.minute) + "m";
|
|
311
|
+
else if (abs >= Time.second) return Math.round(ms / Time.second) + "s";
|
|
312
|
+
return ms + "ms";
|
|
313
|
+
}
|
|
314
|
+
Time.format = format;
|
|
315
|
+
function toDigits(source, length = 2) {
|
|
316
|
+
return source.toString().padStart(length, "0");
|
|
317
|
+
}
|
|
318
|
+
Time.toDigits = toDigits;
|
|
319
|
+
function template(template, time = /* @__PURE__ */ new Date()) {
|
|
320
|
+
return template.replace("yyyy", time.getFullYear().toString()).replace("yy", time.getFullYear().toString().slice(2)).replace("MM", toDigits(time.getMonth() + 1)).replace("dd", toDigits(time.getDate())).replace("hh", toDigits(time.getHours())).replace("mm", toDigits(time.getMinutes())).replace("ss", toDigits(time.getSeconds())).replace("SSS", toDigits(time.getMilliseconds(), 3));
|
|
321
|
+
}
|
|
322
|
+
Time.template = template;
|
|
323
|
+
})(Time || (Time = {}));
|
|
324
|
+
//#endregion
|
|
325
|
+
export { Binary, Time, arrayBufferToBase64, arrayBufferToHex, base64ToArrayBuffer, camelCase, camelize, capitalize, clone, contain, deduplicate, deepEqual, defineProperty, difference, filterKeys, formatProperty, hexToArrayBuffer, hyphenate, intersection, is, isNonNullable, isNullable, isPlainObject, makeArray, mapValues, mapValues as valueMap, noop, omit, paramCase, pick, remove, sanitize, snakeCase, trimSlash, uncapitalize, union };
|