t1y-sdk-js 5.0.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/LICENSE +21 -0
- package/README.md +313 -0
- package/README.zh-CN.md +313 -0
- package/dist/index.d.mts +920 -0
- package/dist/index.d.ts +920 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +1 -0
- package/dist/umd/t1y.min.js +2 -0
- package/package.json +69 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,920 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for initializing the t1yOS client.
|
|
3
|
+
*/
|
|
4
|
+
interface T1YOSConfig {
|
|
5
|
+
/** Base URL of the t1yOS platform. Default: 'https://myapp.t1y.net' */
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
/** Application ID. Required, must be an integer >= 1001 */
|
|
8
|
+
appId: number;
|
|
9
|
+
/** API Key. Required, must be exactly 32 characters */
|
|
10
|
+
apiKey: string;
|
|
11
|
+
/** Secret Key. Required, must be exactly 32 characters */
|
|
12
|
+
secretKey: string;
|
|
13
|
+
/** Application version. Default: 0 */
|
|
14
|
+
version?: number;
|
|
15
|
+
/** Whether to enable safe mode (AES-256-GCM encryption). Default: false */
|
|
16
|
+
isSafeMode?: boolean;
|
|
17
|
+
/** Time format for createdAt/updatedAt fields. Default: 'YYYY-MM-DD HH:mm:ss' */
|
|
18
|
+
timeFormat?: string;
|
|
19
|
+
/** Time offset in seconds between client and server. Default: 0 */
|
|
20
|
+
offset?: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Internal configuration with all optional fields resolved to defaults.
|
|
24
|
+
*/
|
|
25
|
+
interface T1YOSInternalConfig {
|
|
26
|
+
baseUrl: string;
|
|
27
|
+
appId: number;
|
|
28
|
+
apiKey: string;
|
|
29
|
+
secretKey: string;
|
|
30
|
+
version: number;
|
|
31
|
+
isSafeMode: boolean;
|
|
32
|
+
timeFormat: string;
|
|
33
|
+
offset: number;
|
|
34
|
+
}
|
|
35
|
+
/** HTTP methods supported by the SDK */
|
|
36
|
+
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Standard API response wrapper returned by the t1yOS server.
|
|
40
|
+
*/
|
|
41
|
+
interface ApiResponse<T = unknown> {
|
|
42
|
+
code: number;
|
|
43
|
+
message: string;
|
|
44
|
+
data: T;
|
|
45
|
+
}
|
|
46
|
+
/** Response from insertOne */
|
|
47
|
+
interface InsertResult {
|
|
48
|
+
objectId: string;
|
|
49
|
+
}
|
|
50
|
+
/** Response from insertMany */
|
|
51
|
+
interface InsertManyResult {
|
|
52
|
+
objectIds: string[];
|
|
53
|
+
insertedCount: number;
|
|
54
|
+
}
|
|
55
|
+
/** Response from deleteOne / deleteOneByObjectId */
|
|
56
|
+
interface DeleteResult {
|
|
57
|
+
deletedCount: number;
|
|
58
|
+
}
|
|
59
|
+
/** Response from deleteMany */
|
|
60
|
+
interface DeleteManyResult {
|
|
61
|
+
deletedCount: number;
|
|
62
|
+
}
|
|
63
|
+
/** Response from updateOne / updateOneByObjectId */
|
|
64
|
+
interface UpdateResult {
|
|
65
|
+
modifiedCount: number;
|
|
66
|
+
}
|
|
67
|
+
/** Response from updateMany */
|
|
68
|
+
interface UpdateManyResult {
|
|
69
|
+
modifiedCount: number;
|
|
70
|
+
}
|
|
71
|
+
/** Response from findOne / findOneByObjectId / findOneByFilter */
|
|
72
|
+
interface FindResult {
|
|
73
|
+
result: Record<string, unknown>;
|
|
74
|
+
}
|
|
75
|
+
/** Pagination metadata */
|
|
76
|
+
interface Pagination {
|
|
77
|
+
totalItems: number;
|
|
78
|
+
totalPages: number;
|
|
79
|
+
}
|
|
80
|
+
/** Response from find (paginated query) */
|
|
81
|
+
interface PaginationResult {
|
|
82
|
+
results: Record<string, unknown>[];
|
|
83
|
+
page: number;
|
|
84
|
+
size: number;
|
|
85
|
+
pagination: Pagination;
|
|
86
|
+
}
|
|
87
|
+
/** Response from aggregate */
|
|
88
|
+
interface AggregateResult {
|
|
89
|
+
results: Record<string, unknown>[];
|
|
90
|
+
}
|
|
91
|
+
/** Init response from GET /init/:appId */
|
|
92
|
+
interface InitResult {
|
|
93
|
+
unix: number;
|
|
94
|
+
is_safe_mode: boolean;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Marker type string representations that the server's GetDataTypes()
|
|
99
|
+
* recognizes and converts to native MongoDB/Go types.
|
|
100
|
+
*
|
|
101
|
+
* These are all literal string types for documentation/typing purposes.
|
|
102
|
+
* At runtime, the helper functions simply return these string values.
|
|
103
|
+
*/
|
|
104
|
+
/** ObjectID marker: ObjectID('24-char-hex') */
|
|
105
|
+
type ObjectIDMarker = `ObjectID('${string}')`;
|
|
106
|
+
/** Date marker: Date('RFC3339') */
|
|
107
|
+
type DateMarker = `Date('${string}')`;
|
|
108
|
+
/** DateTime marker: DateTime('RFC3339') */
|
|
109
|
+
type DateTimeMarker = `DateTime('${string}')`;
|
|
110
|
+
/** Timestamp marker: Timestamp('unix-seconds') */
|
|
111
|
+
type TimestampMarker = `Timestamp('${string}')`;
|
|
112
|
+
/** Boolean marker: Boolean(true) or Boolean(false) */
|
|
113
|
+
type BooleanMarker = `Boolean(${string})`;
|
|
114
|
+
/** Integer marker: Integer(N) */
|
|
115
|
+
type IntegerMarker = `Integer(${number})`;
|
|
116
|
+
/** Bigint marker: Bigint(N) */
|
|
117
|
+
type BigintMarker = `Bigint(${number})`;
|
|
118
|
+
/** Float marker: Float(N) */
|
|
119
|
+
type FloatMarker = `Float(${number})`;
|
|
120
|
+
/** Double marker: Double(N) */
|
|
121
|
+
type DoubleMarker = `Double(${number})`;
|
|
122
|
+
/** Array marker: Array(json) */
|
|
123
|
+
type ArrayMarker = `Array(${string})`;
|
|
124
|
+
/** Map marker: Map(json) */
|
|
125
|
+
type MapMarker = `Map(${string})`;
|
|
126
|
+
/** Map[] marker: Map[](json) */
|
|
127
|
+
type MapArrayMarker = `Map[](${string})`;
|
|
128
|
+
/** Null markers that the server converts to nil */
|
|
129
|
+
type NullMarker = 'Null' | 'null' | 'NULL' | 'None' | 'none' | 'NONE' | 'Nil' | 'nil' | 'NIL' | '<nil>' | '';
|
|
130
|
+
/** Undefined markers that the server converts to bson.Undefined */
|
|
131
|
+
type UndefinedMarker = 'UNDEFINED' | 'Undefined';
|
|
132
|
+
/** Time helper markers */
|
|
133
|
+
type TimeNowMarker = 'time.Now()';
|
|
134
|
+
type TimeNowUnixMarker = 'time.Now().Unix()';
|
|
135
|
+
type TimeNowUnixNanoMarker = 'time.Now().UnixNano()';
|
|
136
|
+
type TimeNowWeekdayMarker = 'time.Now().Weekday()';
|
|
137
|
+
type TimeNowWeekdayChineseMarker = 'time.Now().Weekday().Chinese()';
|
|
138
|
+
/**
|
|
139
|
+
* Union of all possible special type marker strings.
|
|
140
|
+
*/
|
|
141
|
+
type SpecialTypeMarker = ObjectIDMarker | DateMarker | DateTimeMarker | TimestampMarker | BooleanMarker | IntegerMarker | BigintMarker | FloatMarker | DoubleMarker | ArrayMarker | MapMarker | MapArrayMarker | NullMarker | UndefinedMarker | TimeNowMarker | TimeNowUnixMarker | TimeNowUnixNanoMarker | TimeNowWeekdayMarker | TimeNowWeekdayChineseMarker;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* T1Collection — Database collection class providing chainable CRUD and schema operations.
|
|
145
|
+
*
|
|
146
|
+
* Created via `client.db.collection('name')` — never instantiated directly.
|
|
147
|
+
*/
|
|
148
|
+
|
|
149
|
+
declare class T1Collection {
|
|
150
|
+
/** The parent T1YOS client */
|
|
151
|
+
private client;
|
|
152
|
+
/** The collection (table) name */
|
|
153
|
+
private name;
|
|
154
|
+
/**
|
|
155
|
+
* @internal — Use `client.db.collection(name)` instead.
|
|
156
|
+
*/
|
|
157
|
+
constructor(client: T1YOS, name: string);
|
|
158
|
+
/**
|
|
159
|
+
* Insert one document into the collection.
|
|
160
|
+
*
|
|
161
|
+
* @param data - Document data (must be a non-empty plain object)
|
|
162
|
+
* @returns Response with the inserted document's ObjectID
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* const { data } = await client.db.collection('users').insertOne({
|
|
167
|
+
* name: 'Alice',
|
|
168
|
+
* age: 25,
|
|
169
|
+
* })
|
|
170
|
+
* console.log(data.objectId) // '507f1f77bcf86cd799439011'
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
insertOne(data: Record<string, unknown>): Promise<ApiResponse<InsertResult>>;
|
|
174
|
+
/**
|
|
175
|
+
* Delete one document by ObjectID.
|
|
176
|
+
*
|
|
177
|
+
* @param objectId - 24-character hex ObjectID string
|
|
178
|
+
* @returns Response with deleted count
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```ts
|
|
182
|
+
* await client.db.collection('users').deleteById('507f1f77bcf86cd799439011')
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
deleteById(objectId: string): Promise<ApiResponse<DeleteResult>>;
|
|
186
|
+
/**
|
|
187
|
+
* Update one document by ObjectID.
|
|
188
|
+
*
|
|
189
|
+
* @param objectId - 24-character hex ObjectID string
|
|
190
|
+
* @param data - Update data (must be a non-empty plain object)
|
|
191
|
+
* @returns Response with modified count
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```ts
|
|
195
|
+
* await client.db.collection('users').updateById('507f1f77bcf86cd799439011', { name: 'Bob' })
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
updateById(objectId: string, data: Record<string, unknown>): Promise<ApiResponse<UpdateResult>>;
|
|
199
|
+
/**
|
|
200
|
+
* Find one document by ObjectID.
|
|
201
|
+
*
|
|
202
|
+
* @param objectId - 24-character hex ObjectID string
|
|
203
|
+
* @returns Response with the found document
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* const { data } = await client.db.collection('users').findById('507f1f77bcf86cd799439011')
|
|
208
|
+
* console.log(data.result) // { _id: '507f1f77...', name: 'Alice', ... }
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
findById(objectId: string): Promise<ApiResponse<FindResult>>;
|
|
212
|
+
/**
|
|
213
|
+
* Delete one document matching the filter.
|
|
214
|
+
*
|
|
215
|
+
* @param filter - Query filter (must be a non-empty plain object)
|
|
216
|
+
* @returns Response with deleted count
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```ts
|
|
220
|
+
* await client.db.collection('users').deleteOne({ name: 'Alice' })
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
deleteOne(filter: Record<string, unknown>): Promise<ApiResponse<DeleteResult>>;
|
|
224
|
+
/**
|
|
225
|
+
* Update one document matching the filter.
|
|
226
|
+
*
|
|
227
|
+
* @param filter - Query filter to find the document
|
|
228
|
+
* @param body - Update data (MongoDB update operators like $set, $inc, etc.)
|
|
229
|
+
* @returns Response with modified count
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```ts
|
|
233
|
+
* await client.db.collection('users').updateOne(
|
|
234
|
+
* { name: 'Alice' },
|
|
235
|
+
* { $set: { age: 26 } }
|
|
236
|
+
* )
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
239
|
+
updateOne(filter: Record<string, unknown>, body: Record<string, unknown>): Promise<ApiResponse<UpdateResult>>;
|
|
240
|
+
/**
|
|
241
|
+
* Find one document matching the filter.
|
|
242
|
+
*
|
|
243
|
+
* @param filter - Query filter
|
|
244
|
+
* @returns Response with the found document (or null if not found)
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```ts
|
|
248
|
+
* const { data } = await client.db.collection('users').findOne({ name: 'Alice' })
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
findOne(filter: Record<string, unknown>): Promise<ApiResponse<FindResult>>;
|
|
252
|
+
/**
|
|
253
|
+
* Insert multiple documents into the collection.
|
|
254
|
+
*
|
|
255
|
+
* @param dataList - Array of document data (each must be a non-empty plain object)
|
|
256
|
+
* @returns Response with inserted ObjectIDs and count
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* ```ts
|
|
260
|
+
* const { data } = await client.db.collection('users').insertMany([
|
|
261
|
+
* { name: 'Alice', age: 25 },
|
|
262
|
+
* { name: 'Bob', age: 30 },
|
|
263
|
+
* ])
|
|
264
|
+
* console.log(data.insertedCount) // 2
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
insertMany(dataList: Record<string, unknown>[]): Promise<ApiResponse<InsertManyResult>>;
|
|
268
|
+
/**
|
|
269
|
+
* Delete multiple documents matching the filter.
|
|
270
|
+
*
|
|
271
|
+
* @param filter - Query filter (can be an empty object to match all)
|
|
272
|
+
* @returns Response with deleted count
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```ts
|
|
276
|
+
* const { data } = await client.db.collection('users').deleteMany({ age: { $lt: 18 } })
|
|
277
|
+
* console.log(data.deletedCount) // 5
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
deleteMany(filter: Record<string, unknown>): Promise<ApiResponse<DeleteManyResult>>;
|
|
281
|
+
/**
|
|
282
|
+
* Update multiple documents matching the filter.
|
|
283
|
+
*
|
|
284
|
+
* @param filter - Query filter to match documents
|
|
285
|
+
* @param body - Update data (MongoDB update operators)
|
|
286
|
+
* @returns Response with modified count
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```ts
|
|
290
|
+
* await client.db.collection('users').updateMany(
|
|
291
|
+
* { status: 'inactive' },
|
|
292
|
+
* { $set: { status: 'archived' } }
|
|
293
|
+
* )
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
updateMany(filter: Record<string, unknown>, body: Record<string, unknown>): Promise<ApiResponse<UpdateManyResult>>;
|
|
297
|
+
/**
|
|
298
|
+
* Paginated find query with sorting and filtering.
|
|
299
|
+
*
|
|
300
|
+
* @param page - Page number (1-based, default: 1)
|
|
301
|
+
* @param size - Page size (1-100, default: 10)
|
|
302
|
+
* @param sort - Sort specification, e.g. `{ createdAt: -1 }` for newest first
|
|
303
|
+
* @param filter - Query filter
|
|
304
|
+
* @returns Response with paginated results and pagination metadata
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* ```ts
|
|
308
|
+
* const { data } = await client.db.collection('users').find(
|
|
309
|
+
* 1, // page
|
|
310
|
+
* 20, // size
|
|
311
|
+
* { createdAt: -1 }, // sort (newest first)
|
|
312
|
+
* { age: { $gte: 18 } } // filter
|
|
313
|
+
* )
|
|
314
|
+
* console.log(data.results) // Array of documents
|
|
315
|
+
* console.log(data.pagination) // { totalItems: 100, totalPages: 5 }
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
find(page?: number, size?: number, sort?: Record<string, number>, filter?: Record<string, unknown>): Promise<ApiResponse<PaginationResult>>;
|
|
319
|
+
/**
|
|
320
|
+
* Execute a MongoDB aggregation pipeline.
|
|
321
|
+
*
|
|
322
|
+
* @param pipeline - Array of aggregation stages
|
|
323
|
+
* @returns Response with aggregation results
|
|
324
|
+
*
|
|
325
|
+
* @example
|
|
326
|
+
* ```ts
|
|
327
|
+
* const { data } = await client.db.collection('orders').aggregate([
|
|
328
|
+
* { $match: { status: 'completed' } },
|
|
329
|
+
* { $group: { _id: '$category', total: { $sum: '$amount' } } },
|
|
330
|
+
* { $sort: { total: -1 } },
|
|
331
|
+
* ])
|
|
332
|
+
* ```
|
|
333
|
+
*/
|
|
334
|
+
aggregate(pipeline: Record<string, unknown>[]): Promise<ApiResponse<AggregateResult>>;
|
|
335
|
+
/**
|
|
336
|
+
* Count documents matching a filter.
|
|
337
|
+
*
|
|
338
|
+
* Uses `POST /v5/classes/:name/count` with the filter as the request body.
|
|
339
|
+
*
|
|
340
|
+
* @param filter - Query filter (can be an empty object for total count)
|
|
341
|
+
* @returns Response with `data.count`
|
|
342
|
+
*
|
|
343
|
+
* @example
|
|
344
|
+
* ```ts
|
|
345
|
+
* const { data } = await client.db.collection('users').count({ status: 'active' })
|
|
346
|
+
* console.log(data.count) // 42
|
|
347
|
+
* ```
|
|
348
|
+
*/
|
|
349
|
+
count(filter?: Record<string, unknown>): Promise<ApiResponse<{
|
|
350
|
+
count: number;
|
|
351
|
+
}>>;
|
|
352
|
+
/**
|
|
353
|
+
* Get distinct values for a field, optionally filtered.
|
|
354
|
+
*
|
|
355
|
+
* Uses `POST /v5/classes/:name/distinct/:field` with the filter as the request body.
|
|
356
|
+
*
|
|
357
|
+
* @param fieldName - The field to get distinct values for
|
|
358
|
+
* @param filter - Optional filter to narrow the documents
|
|
359
|
+
* @returns Response with `data.results` containing distinct values
|
|
360
|
+
*
|
|
361
|
+
* @example
|
|
362
|
+
* ```ts
|
|
363
|
+
* const { data } = await client.db.collection('users').distinct('city')
|
|
364
|
+
* console.log(data.results) // ['Beijing', 'Shanghai', ...]
|
|
365
|
+
* ```
|
|
366
|
+
*/
|
|
367
|
+
distinct(fieldName: string, filter?: Record<string, unknown>): Promise<ApiResponse<{
|
|
368
|
+
results: unknown[];
|
|
369
|
+
}>>;
|
|
370
|
+
/**
|
|
371
|
+
* Create this collection (table) in the application's database.
|
|
372
|
+
*
|
|
373
|
+
* @example
|
|
374
|
+
* ```ts
|
|
375
|
+
* await client.db.collection('posts').create()
|
|
376
|
+
* ```
|
|
377
|
+
*/
|
|
378
|
+
create(): Promise<ApiResponse>;
|
|
379
|
+
/**
|
|
380
|
+
* Clear all documents from this collection without dropping it.
|
|
381
|
+
*
|
|
382
|
+
* @returns Response with `data.deletedCount`
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
* ```ts
|
|
386
|
+
* const { data } = await client.db.collection('temp').clear()
|
|
387
|
+
* console.log(data.deletedCount) // 150
|
|
388
|
+
* ```
|
|
389
|
+
*/
|
|
390
|
+
clear(): Promise<ApiResponse<{
|
|
391
|
+
deletedCount: number;
|
|
392
|
+
}>>;
|
|
393
|
+
/**
|
|
394
|
+
* Drop (delete) this collection entirely.
|
|
395
|
+
*
|
|
396
|
+
* @example
|
|
397
|
+
* ```ts
|
|
398
|
+
* await client.db.collection('old_collection').drop()
|
|
399
|
+
* ```
|
|
400
|
+
*/
|
|
401
|
+
drop(): Promise<ApiResponse>;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* T1YOS — Main client class for the t1yOS Serverless Platform SDK.
|
|
406
|
+
*
|
|
407
|
+
* Provides:
|
|
408
|
+
* - Initialization with server time sync
|
|
409
|
+
* - Chainable database operations via `db.collection(name)`
|
|
410
|
+
* - Cloud function invocation
|
|
411
|
+
* - Metadata retrieval
|
|
412
|
+
* - Cryptographic utilities
|
|
413
|
+
*/
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Main T1Y client class.
|
|
417
|
+
*
|
|
418
|
+
* @example
|
|
419
|
+
* ```ts
|
|
420
|
+
* import { T1YOS } from 't1y-sdk-js'
|
|
421
|
+
*
|
|
422
|
+
* const client = new T1YOS({
|
|
423
|
+
* appId: 1001,
|
|
424
|
+
* apiKey: '4fd7448cdc684431a62d8a0111dc6973',
|
|
425
|
+
* secretKey: '17b784e359c946ffa65eebbf9ce29752',
|
|
426
|
+
* })
|
|
427
|
+
*
|
|
428
|
+
* await client.init()
|
|
429
|
+
*
|
|
430
|
+
* // Database operations
|
|
431
|
+
* const { data } = await client.db.collection('users').insertOne({ name: 'Alice' })
|
|
432
|
+
* ```
|
|
433
|
+
*/
|
|
434
|
+
declare class T1YOS {
|
|
435
|
+
#private;
|
|
436
|
+
private config;
|
|
437
|
+
/**
|
|
438
|
+
* Database accessor providing chainable collection operations.
|
|
439
|
+
*
|
|
440
|
+
* @example
|
|
441
|
+
* ```ts
|
|
442
|
+
* await client.db.collection('users').insertOne({ name: 'Alice' })
|
|
443
|
+
* await client.db.collection('users').findOne({ name: 'Alice' })
|
|
444
|
+
* ```
|
|
445
|
+
*/
|
|
446
|
+
readonly db: {
|
|
447
|
+
collection: (name: string) => T1Collection;
|
|
448
|
+
toObjectID: (id: string) => string;
|
|
449
|
+
getCollections: () => Promise<ApiResponse<{
|
|
450
|
+
results: string[];
|
|
451
|
+
}>>;
|
|
452
|
+
};
|
|
453
|
+
/**
|
|
454
|
+
* Create a new T1YOS client instance.
|
|
455
|
+
*
|
|
456
|
+
* @param config - Client configuration (appId, apiKey, secretKey are required)
|
|
457
|
+
*
|
|
458
|
+
* @throws {ValidationError} If required parameters are invalid
|
|
459
|
+
*/
|
|
460
|
+
constructor(config: T1YOSConfig);
|
|
461
|
+
/**
|
|
462
|
+
* Initialize the SDK by syncing with the server.
|
|
463
|
+
*
|
|
464
|
+
* Calls `GET /init/:appId` to:
|
|
465
|
+
* 1. Get the server's current UTC Unix timestamp
|
|
466
|
+
* 2. Get the server's isSafeMode setting
|
|
467
|
+
*
|
|
468
|
+
* The time offset is computed as: `server.unix - client.unix`
|
|
469
|
+
* This offset is used for all subsequent request signing to prevent clock skew issues.
|
|
470
|
+
*
|
|
471
|
+
* @throws {T1YError} If the server returns an error (e.g., app not found, app disabled)
|
|
472
|
+
*/
|
|
473
|
+
init(): Promise<void>;
|
|
474
|
+
/**
|
|
475
|
+
* Get application metadata.
|
|
476
|
+
*
|
|
477
|
+
* @param field - Optional field name to retrieve a specific metadata field
|
|
478
|
+
* @returns Metadata as key-value pairs, or a single field value if `field` is specified
|
|
479
|
+
*
|
|
480
|
+
* @example
|
|
481
|
+
* ```ts
|
|
482
|
+
* // Get all metadata
|
|
483
|
+
* const { data } = await client.getMeta()
|
|
484
|
+
* // data.results = { version: 1, collections: [...] }
|
|
485
|
+
*
|
|
486
|
+
* // Get a specific field
|
|
487
|
+
* const { data } = await client.getMeta('version')
|
|
488
|
+
* // data.result = 1
|
|
489
|
+
* ```
|
|
490
|
+
*/
|
|
491
|
+
getMeta(field?: string): Promise<ApiResponse>;
|
|
492
|
+
/**
|
|
493
|
+
* Check if there's a newer version of the application available.
|
|
494
|
+
*
|
|
495
|
+
* Compares the server's `version` metadata field against the configured `version`.
|
|
496
|
+
*
|
|
497
|
+
* @returns `true` if the server version is greater than the client version
|
|
498
|
+
*/
|
|
499
|
+
checkUpdate(): Promise<boolean>;
|
|
500
|
+
/**
|
|
501
|
+
* Call a cloud function (`.jsc` file).
|
|
502
|
+
*
|
|
503
|
+
* If `name` doesn't end with `.jsc`, it's auto-appended.
|
|
504
|
+
* If `name` ends with `/`, `index.jsc` is appended.
|
|
505
|
+
* If `name` ends with `.js`, it's replaced with `.jsc`.
|
|
506
|
+
*
|
|
507
|
+
* @param name - Function name or path (e.g., 'hello' or 'hello.jsc')
|
|
508
|
+
* @param params - Parameters to pass to the function
|
|
509
|
+
* @param enableSafeMode - Override safe mode for this call (defaults to client setting)
|
|
510
|
+
*
|
|
511
|
+
* @example
|
|
512
|
+
* ```ts
|
|
513
|
+
* const { data } = await client.callFunc('hello', { name: 'World' })
|
|
514
|
+
* ```
|
|
515
|
+
*/
|
|
516
|
+
callFunc(name: string, params?: unknown, enableSafeMode?: boolean): Promise<ApiResponse>;
|
|
517
|
+
/**
|
|
518
|
+
* Core HTTP request method with full authentication and encryption.
|
|
519
|
+
*
|
|
520
|
+
* @param method - HTTP method (GET, POST, PUT, DELETE)
|
|
521
|
+
* @param path - API path (e.g., /v5/classes/users)
|
|
522
|
+
* @param params - Request parameters/body
|
|
523
|
+
* @param encryption - Override encryption (defaults to client.isSafeMode)
|
|
524
|
+
* @returns Typed API response
|
|
525
|
+
*
|
|
526
|
+
* @throws {T1YError} On API errors (non-2xx responses)
|
|
527
|
+
* @throws {Error} On network errors or timeouts
|
|
528
|
+
*/
|
|
529
|
+
request<T = unknown>(method: HttpMethod, path: string, params?: unknown, encryption?: boolean): Promise<ApiResponse<T>>;
|
|
530
|
+
/**
|
|
531
|
+
* Validate an ObjectID hex string.
|
|
532
|
+
*
|
|
533
|
+
* @param idStr - 24-character hex string to validate
|
|
534
|
+
* @param name - Optional name for error messages (default: 'ObjectID')
|
|
535
|
+
* @returns `true` if valid
|
|
536
|
+
* @throws {ValidationError} If the string is not a valid ObjectID
|
|
537
|
+
*/
|
|
538
|
+
assertObjectID(idStr: string, name?: string): boolean;
|
|
539
|
+
/** Check if a value is a non-null, non-array object with at least one key */
|
|
540
|
+
isNonEmptyObject(value: unknown): boolean;
|
|
541
|
+
/** Check if a value is a plain object (non-null, non-array) */
|
|
542
|
+
isPlainObject(value: unknown): boolean;
|
|
543
|
+
/** Check if a value is a non-empty array where every element is a non-empty object */
|
|
544
|
+
isNonEmptyArrayWithNonEmptyObjects(value: unknown): boolean;
|
|
545
|
+
/**
|
|
546
|
+
* Compute HMAC-SHA256 hash and return hex digest.
|
|
547
|
+
*
|
|
548
|
+
* @param message - The message to sign
|
|
549
|
+
* @param secret - The secret key
|
|
550
|
+
* @returns 64-character hex-encoded HMAC-SHA256
|
|
551
|
+
*/
|
|
552
|
+
hmacSHA256(secret: string, message: string): string;
|
|
553
|
+
/**
|
|
554
|
+
* Verify an HMAC-SHA256 signature using constant-time comparison.
|
|
555
|
+
*
|
|
556
|
+
* @param secret - The secret key
|
|
557
|
+
* @param message - The message that was signed
|
|
558
|
+
* @param signature - The expected signature (hex string)
|
|
559
|
+
* @returns `true` if the signature matches
|
|
560
|
+
*/
|
|
561
|
+
verifyHmacSHA256(secret: string, message: string, signature: string): boolean;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Create an ObjectID marker string that the server will convert to a MongoDB ObjectID.
|
|
566
|
+
*
|
|
567
|
+
* @param id - 24-character hexadecimal string
|
|
568
|
+
* @returns ObjectID marker string, e.g. `ObjectID('507f1f77bcf86cd799439011')`
|
|
569
|
+
*
|
|
570
|
+
* @example
|
|
571
|
+
* ```ts
|
|
572
|
+
* import { ObjectID } from 't1y-sdk-js'
|
|
573
|
+
*
|
|
574
|
+
* await db.collection('users').find(ObjectID('507f1f77bcf86cd799439011'))
|
|
575
|
+
* ```
|
|
576
|
+
*/
|
|
577
|
+
declare function ObjectID(id: string): `ObjectID('${string}')`;
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* Create a Date marker string. The server converts this to a Go time.Time.
|
|
581
|
+
*
|
|
582
|
+
* @param dateStr - ISO 8601 / RFC 3339 date string
|
|
583
|
+
* @returns Date marker, e.g. `Date('2024-01-15T10:30:00Z')`
|
|
584
|
+
*/
|
|
585
|
+
declare function Date_(dateStr: string): `Date('${string}')`;
|
|
586
|
+
/**
|
|
587
|
+
* Create a DateTime marker string. Same as Date on the server side.
|
|
588
|
+
*
|
|
589
|
+
* @param dateStr - ISO 8601 / RFC 3339 date string
|
|
590
|
+
* @returns DateTime marker, e.g. `DateTime('2024-01-15T10:30:00Z')`
|
|
591
|
+
*/
|
|
592
|
+
declare function DateTime(dateStr: string): `DateTime('${string}')`;
|
|
593
|
+
/**
|
|
594
|
+
* Create a Timestamp marker string. The server converts this to a Unix timestamp.
|
|
595
|
+
*
|
|
596
|
+
* @param unix - Unix timestamp (seconds) as number or string
|
|
597
|
+
* @returns Timestamp marker, e.g. `Timestamp('1705312200')`
|
|
598
|
+
*/
|
|
599
|
+
declare function Timestamp(unix: number | string): `Timestamp('${string}')`;
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Create a Boolean marker. The server converts this to a Go bool.
|
|
603
|
+
*/
|
|
604
|
+
declare function Boolean_(val: boolean): `Boolean(${string})`;
|
|
605
|
+
/**
|
|
606
|
+
* Create an Integer marker. The server converts this to int32.
|
|
607
|
+
*/
|
|
608
|
+
declare function Integer(n: number): `Integer(${number})`;
|
|
609
|
+
/**
|
|
610
|
+
* Create a Bigint marker. The server converts this to int64.
|
|
611
|
+
*/
|
|
612
|
+
declare function Bigint(n: number | bigint): `Bigint(${number})`;
|
|
613
|
+
/**
|
|
614
|
+
* Create a Float marker. The server converts this to float32.
|
|
615
|
+
*/
|
|
616
|
+
declare function Float(n: number): `Float(${number})`;
|
|
617
|
+
/**
|
|
618
|
+
* Create a Double marker. The server converts this to float64.
|
|
619
|
+
*/
|
|
620
|
+
declare function Double(n: number): `Double(${number})`;
|
|
621
|
+
|
|
622
|
+
/**
|
|
623
|
+
* Create an Array marker. The server converts this to a Go slice.
|
|
624
|
+
*
|
|
625
|
+
* @param arr - Array to serialize as JSON
|
|
626
|
+
*/
|
|
627
|
+
declare function Array_(arr: unknown[]): `Array(${string})`;
|
|
628
|
+
/**
|
|
629
|
+
* Create a Map marker. The server converts this to a map[string]interface{}.
|
|
630
|
+
*
|
|
631
|
+
* @param obj - Object to serialize as JSON
|
|
632
|
+
*/
|
|
633
|
+
declare function Map_(obj: Record<string, unknown>): `Map(${string})`;
|
|
634
|
+
/**
|
|
635
|
+
* Create a Map[] marker. The server converts this to []map[string]interface{}.
|
|
636
|
+
*
|
|
637
|
+
* @param arr - Array of objects to serialize as JSON
|
|
638
|
+
*/
|
|
639
|
+
declare function MapArray(arr: Record<string, unknown>[]): `Map[](${string})`;
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Null / null-equivalent markers that the server converts to Go nil.
|
|
643
|
+
*
|
|
644
|
+
* The server recognizes all these variants as null:
|
|
645
|
+
* 'Null', 'null', 'NULL', 'None', 'none', 'NONE', 'Nil', 'nil', 'NIL', '<nil>', ''
|
|
646
|
+
*/
|
|
647
|
+
/** Null marker — server converts to nil */
|
|
648
|
+
declare const Null: "Null";
|
|
649
|
+
/** None marker — server converts to nil */
|
|
650
|
+
declare const None: "None";
|
|
651
|
+
/** Nil marker — server converts to nil */
|
|
652
|
+
declare const Nil: "Nil";
|
|
653
|
+
/** empty string — server converts to nil (use '' directly) */
|
|
654
|
+
declare const Empty: "";
|
|
655
|
+
/**
|
|
656
|
+
* Undefined markers that the server converts to bson.Undefined{}.
|
|
657
|
+
*/
|
|
658
|
+
declare const UNDEFINED: "UNDEFINED";
|
|
659
|
+
declare const Undefined: "Undefined";
|
|
660
|
+
|
|
661
|
+
/**
|
|
662
|
+
* Time helper markers that the server evaluates at request time.
|
|
663
|
+
*
|
|
664
|
+
* These are string values that, when sent to the server, are replaced
|
|
665
|
+
* with the actual current time on the server side via Go's time.Now().
|
|
666
|
+
*/
|
|
667
|
+
/** Server fills in time.Now() (current UTC time) */
|
|
668
|
+
declare const TimeNow: "time.Now()";
|
|
669
|
+
/** Server fills in time.Now().Unix() (current Unix timestamp) */
|
|
670
|
+
declare const TimeNowUnix: "time.Now().Unix()";
|
|
671
|
+
/** Server fills in time.Now().UnixNano() */
|
|
672
|
+
declare const TimeNowUnixNano: "time.Now().UnixNano()";
|
|
673
|
+
/** Server fills in time.Now().Weekday() (e.g., time.Monday) */
|
|
674
|
+
declare const TimeNowWeekday: "time.Now().Weekday()";
|
|
675
|
+
/** Server fills in time.Now().Weekday().Chinese() (Chinese weekday name) */
|
|
676
|
+
declare const TimeNowWeekdayChinese: "time.Now().Weekday().Chinese()";
|
|
677
|
+
/**
|
|
678
|
+
* Convenience object grouping all time-now helpers.
|
|
679
|
+
*
|
|
680
|
+
* @example
|
|
681
|
+
* ```ts
|
|
682
|
+
* import { timeNow } from 't1y-sdk-js'
|
|
683
|
+
*
|
|
684
|
+
* await db.collection('posts').insertOne({
|
|
685
|
+
* title: 'Hello',
|
|
686
|
+
* createdAt: timeNow.Now(),
|
|
687
|
+
* })
|
|
688
|
+
* ```
|
|
689
|
+
*/
|
|
690
|
+
declare const timeNow: {
|
|
691
|
+
Now: () => "time.Now()";
|
|
692
|
+
NowUnix: () => "time.Now().Unix()";
|
|
693
|
+
NowUnixNano: () => "time.Now().UnixNano()";
|
|
694
|
+
NowWeekday: () => "time.Now().Weekday()";
|
|
695
|
+
NowWeekdayChinese: () => "time.Now().Weekday().Chinese()";
|
|
696
|
+
};
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* SHA-256 hashing — works in both Node.js and browser environments.
|
|
700
|
+
*
|
|
701
|
+
* Node.js (CJS): Uses node:crypto (synchronous via require)
|
|
702
|
+
* Node.js (ESM): Falls back to pure-JS (works correctly for all byte values)
|
|
703
|
+
* Browser: Uses pure-JS implementation
|
|
704
|
+
*/
|
|
705
|
+
/**
|
|
706
|
+
* Compute the SHA-256 hash of a string and return the hex digest.
|
|
707
|
+
*
|
|
708
|
+
* For the signing path: the input is always a UTF-8 string
|
|
709
|
+
* (method, URL, body JSON, etc.), so this works correctly.
|
|
710
|
+
*
|
|
711
|
+
* For raw binary data (from HMAC inner hash), use sha256RawBytesHex instead.
|
|
712
|
+
*
|
|
713
|
+
* @param data - Input string to hash (UTF-8)
|
|
714
|
+
* @returns Hex-encoded SHA-256 hash (64 hex characters)
|
|
715
|
+
*/
|
|
716
|
+
declare function sha256Hex(data: string): string;
|
|
717
|
+
/**
|
|
718
|
+
* Compute SHA-256 hash asynchronously using Web Crypto API.
|
|
719
|
+
*/
|
|
720
|
+
declare function sha256HexAsync(data: string): Promise<string>;
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* HMAC-SHA256 implementation — works in both Node.js and browser environments.
|
|
724
|
+
*
|
|
725
|
+
* Node.js (CJS): Uses node:crypto (synchronous via require)
|
|
726
|
+
* Browser / ESM: Uses pure-JS implementation operating on Uint8Array
|
|
727
|
+
*/
|
|
728
|
+
/**
|
|
729
|
+
* Compute HMAC-SHA256 and return hex digest.
|
|
730
|
+
*
|
|
731
|
+
* This is intentionally synchronous because it's called in the request
|
|
732
|
+
* signing path, which must be fast and cannot defer to async.
|
|
733
|
+
*
|
|
734
|
+
* @param secret - The secret key (raw string, used as-is as bytes)
|
|
735
|
+
* @param message - The message to sign
|
|
736
|
+
* @returns Hex-encoded HMAC-SHA256 signature (64 hex characters)
|
|
737
|
+
*/
|
|
738
|
+
declare function hmacSHA256Hex(secret: string, message: string): string;
|
|
739
|
+
/**
|
|
740
|
+
* Compute HMAC-SHA256 asynchronously using Web Crypto API.
|
|
741
|
+
*/
|
|
742
|
+
declare function hmacSHA256HexAsync(secret: string, message: string): Promise<string>;
|
|
743
|
+
/**
|
|
744
|
+
* Verify an HMAC-SHA256 signature using constant-time comparison.
|
|
745
|
+
*/
|
|
746
|
+
declare function verifyHmacSHA256(secret: string, message: string, signature: string): boolean;
|
|
747
|
+
|
|
748
|
+
/**
|
|
749
|
+
* AES-256-GCM encryption and decryption.
|
|
750
|
+
*
|
|
751
|
+
* Compatible with the t1yOS Go server's AES-256-GCM implementation.
|
|
752
|
+
* Payload format: { "n": "<nonce base64>", "j": "<ciphertext base64>", "t": "<tag base64>" }
|
|
753
|
+
*
|
|
754
|
+
* Works in both Node.js and browser via Web Crypto API.
|
|
755
|
+
*/
|
|
756
|
+
/**
|
|
757
|
+
* AES-256-GCM encrypted payload structure.
|
|
758
|
+
* Matches the Go server's AESGCMEncryptedPayload struct.
|
|
759
|
+
*/
|
|
760
|
+
interface AESGCMPayload {
|
|
761
|
+
/** Base64-encoded nonce */
|
|
762
|
+
n: string;
|
|
763
|
+
/** Base64-encoded ciphertext */
|
|
764
|
+
j: string;
|
|
765
|
+
/** Base64-encoded authentication tag */
|
|
766
|
+
t: string;
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* Encrypt data using AES-256-GCM.
|
|
770
|
+
*
|
|
771
|
+
* @param data - The plaintext data to encrypt (string)
|
|
772
|
+
* @param keyBytes - 32-byte encryption key (Uint8Array)
|
|
773
|
+
* @returns JSON string of { n, j, t } payload
|
|
774
|
+
*/
|
|
775
|
+
declare function encryptAESGCM(data: string, keyBytes: Uint8Array): Promise<string>;
|
|
776
|
+
/**
|
|
777
|
+
* Decrypt data using AES-256-GCM.
|
|
778
|
+
*
|
|
779
|
+
* @param jsonPayload - JSON string of { n, j, t } payload
|
|
780
|
+
* @param keyBytes - 32-byte decryption key (Uint8Array)
|
|
781
|
+
* @returns Decrypted plaintext string
|
|
782
|
+
*/
|
|
783
|
+
declare function decryptAESGCM(jsonPayload: string, keyBytes: Uint8Array): Promise<string>;
|
|
784
|
+
|
|
785
|
+
/**
|
|
786
|
+
* Request signing algorithm for T1Y v5 RESTful API authentication.
|
|
787
|
+
*
|
|
788
|
+
* Implements the same signing logic as the Go server's middleware/v5_auth.go:
|
|
789
|
+
*
|
|
790
|
+
* message = METHOD + "\n" + URL_PATH_AND_QUERY + "\n" + SHA256(body) + "\n" + appId + "\n" + timestamp
|
|
791
|
+
* signature = HMAC-SHA256(secretKey, message)
|
|
792
|
+
*/
|
|
793
|
+
/**
|
|
794
|
+
* Parameters for creating a request signature.
|
|
795
|
+
*/
|
|
796
|
+
interface SignatureInput {
|
|
797
|
+
/** HTTP method in uppercase (GET, POST, PUT, DELETE) */
|
|
798
|
+
method: string;
|
|
799
|
+
/** URL path including query string, e.g. /v5/classes/users?field=name */
|
|
800
|
+
pathAndQuery: string;
|
|
801
|
+
/** Request body as a raw string (empty string for GET requests) */
|
|
802
|
+
body: string;
|
|
803
|
+
/** Application ID */
|
|
804
|
+
appId: number;
|
|
805
|
+
/** 10-digit Unix timestamp (UTC + offset) */
|
|
806
|
+
timestamp: number;
|
|
807
|
+
/** 32-character Secret Key */
|
|
808
|
+
secretKey: string;
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* Create an HMAC-SHA256 signature for a T1Y API request.
|
|
812
|
+
*
|
|
813
|
+
* The message format is (each line separated by \n):
|
|
814
|
+
* 1. HTTP method (uppercase)
|
|
815
|
+
* 2. URL path + query string
|
|
816
|
+
* 3. SHA-256 hex digest of the request body
|
|
817
|
+
* 4. Application ID (as string)
|
|
818
|
+
* 5. Unix timestamp (as string)
|
|
819
|
+
*
|
|
820
|
+
* @param input - Signature parameters
|
|
821
|
+
* @returns 64-character hex-encoded HMAC-SHA256 signature
|
|
822
|
+
*
|
|
823
|
+
* @example
|
|
824
|
+
* ```ts
|
|
825
|
+
* const sign = createSignature({
|
|
826
|
+
* method: 'POST',
|
|
827
|
+
* pathAndQuery: '/v5/classes/users',
|
|
828
|
+
* body: '{"name":"Alice"}',
|
|
829
|
+
* appId: 1001,
|
|
830
|
+
* timestamp: 1705312200,
|
|
831
|
+
* secretKey: '17b784e359c946ffa65eebbf9ce29752',
|
|
832
|
+
* })
|
|
833
|
+
* // Set as X-T1Y-Safe-Sign header
|
|
834
|
+
* ```
|
|
835
|
+
*/
|
|
836
|
+
declare function createSignature(input: SignatureInput): string;
|
|
837
|
+
/**
|
|
838
|
+
* Get the current UTC Unix timestamp adjusted by the given offset.
|
|
839
|
+
*
|
|
840
|
+
* @param offset - Time offset in seconds (from server init)
|
|
841
|
+
* @returns 10-digit Unix timestamp string
|
|
842
|
+
*/
|
|
843
|
+
declare function getSafeTimestamp(offset: number): string;
|
|
844
|
+
|
|
845
|
+
/**
|
|
846
|
+
* Custom error class for t1yOS SDK errors.
|
|
847
|
+
* Wraps API error responses with code, message, and data.
|
|
848
|
+
*/
|
|
849
|
+
declare class T1YError extends Error {
|
|
850
|
+
/** HTTP status or error code */
|
|
851
|
+
code: number;
|
|
852
|
+
/** Response data from server (if any) */
|
|
853
|
+
data: unknown;
|
|
854
|
+
constructor(code: number, message: string, data?: unknown);
|
|
855
|
+
toJSON(): Record<string, unknown>;
|
|
856
|
+
}
|
|
857
|
+
/**
|
|
858
|
+
* Validation error thrown when configuration parameters are invalid.
|
|
859
|
+
*/
|
|
860
|
+
declare class ValidationError extends Error {
|
|
861
|
+
constructor(message: string);
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
/**
|
|
865
|
+
* Validate that the application ID is a valid integer >= MIN_APP_ID.
|
|
866
|
+
*/
|
|
867
|
+
declare function validateAppId(appId: number): void;
|
|
868
|
+
/**
|
|
869
|
+
* Validate that the API Key is exactly the required length.
|
|
870
|
+
*/
|
|
871
|
+
declare function validateApiKey(apiKey: string): void;
|
|
872
|
+
/**
|
|
873
|
+
* Validate that the Secret Key is exactly the required length.
|
|
874
|
+
*/
|
|
875
|
+
declare function validateSecretKey(secretKey: string): void;
|
|
876
|
+
/**
|
|
877
|
+
* Validate the base URL format.
|
|
878
|
+
*/
|
|
879
|
+
declare function validateBaseUrl(baseUrl: string): void;
|
|
880
|
+
/**
|
|
881
|
+
* Validate all configuration parameters at once.
|
|
882
|
+
*/
|
|
883
|
+
declare function validateInitConfig(config: T1YOSConfig): void;
|
|
884
|
+
/**
|
|
885
|
+
* Validate an ObjectID hex string.
|
|
886
|
+
* Returns true if valid, throws otherwise.
|
|
887
|
+
*/
|
|
888
|
+
declare function assertObjectID(idStr: string, name?: string): boolean;
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* Recursively convert JavaScript Date objects and timestamp numbers
|
|
892
|
+
* into the marker string format that the server's GetDataTypes() recognizes.
|
|
893
|
+
*
|
|
894
|
+
* - Date objects → `Date('ISO-8601')`
|
|
895
|
+
* - Numbers >= 10 digits → `Timestamp('unix')`
|
|
896
|
+
* - Already-marker strings (starting with recognized prefixes) are passed through
|
|
897
|
+
*/
|
|
898
|
+
declare function convertDateTypes(value: unknown): unknown;
|
|
899
|
+
/**
|
|
900
|
+
* Check if a value is a non-null, non-array object with at least one key.
|
|
901
|
+
*/
|
|
902
|
+
declare function isNonEmptyObject(value: unknown): boolean;
|
|
903
|
+
/**
|
|
904
|
+
* Check if a value is a plain object (non-null, non-array).
|
|
905
|
+
*/
|
|
906
|
+
declare function isPlainObject(value: unknown): boolean;
|
|
907
|
+
/**
|
|
908
|
+
* Check if a value is a non-empty array where every element is a non-empty object.
|
|
909
|
+
*/
|
|
910
|
+
declare function isNonEmptyArrayWithNonEmptyObjects(value: unknown): boolean;
|
|
911
|
+
|
|
912
|
+
/**
|
|
913
|
+
* Recursively convert all `createdAt` and `updatedAt` fields in a data structure
|
|
914
|
+
* from UTC strings to local time formatted strings.
|
|
915
|
+
*
|
|
916
|
+
* Returns a new object/array; does not mutate the original.
|
|
917
|
+
*/
|
|
918
|
+
declare function formatTimestampsToLocal(data: unknown, format?: string): unknown;
|
|
919
|
+
|
|
920
|
+
export { type AESGCMPayload, type AggregateResult, type ApiResponse, Array_ as Array, type ArrayMarker, Bigint, type BigintMarker, Boolean_ as Boolean, type BooleanMarker, Date_ as Date, type DateMarker, DateTime, type DateTimeMarker, type DeleteManyResult, type DeleteResult, Double, type DoubleMarker, Empty, type FindResult, Float, type FloatMarker, type HttpMethod, type InitResult, type InsertManyResult, type InsertResult, Integer, type IntegerMarker, Map_ as Map, MapArray, type MapArrayMarker, type MapMarker, Nil, None, Null, type NullMarker, ObjectID, type ObjectIDMarker, type Pagination, type PaginationResult, type SignatureInput, type SpecialTypeMarker, T1Collection, T1YError, T1YOS, type T1YOSConfig, type T1YOSInternalConfig, TimeNow, type TimeNowMarker, TimeNowUnix, type TimeNowUnixMarker, TimeNowUnixNano, type TimeNowUnixNanoMarker, TimeNowWeekday, TimeNowWeekdayChinese, type TimeNowWeekdayChineseMarker, type TimeNowWeekdayMarker, Timestamp, type TimestampMarker, UNDEFINED, Undefined, type UndefinedMarker, type UpdateManyResult, type UpdateResult, ValidationError, assertObjectID, convertDateTypes, createSignature, decryptAESGCM, T1YOS as default, encryptAESGCM, formatTimestampsToLocal, getSafeTimestamp, hmacSHA256Hex, hmacSHA256HexAsync, isNonEmptyArrayWithNonEmptyObjects, isNonEmptyObject, isPlainObject, sha256Hex, sha256HexAsync, timeNow, validateApiKey, validateAppId, validateBaseUrl, validateInitConfig, validateSecretKey, verifyHmacSHA256 };
|