@downcity/services 0.1.6

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 (78) hide show
  1. package/README.md +47 -0
  2. package/bin/accounts/db.d.ts +19 -0
  3. package/bin/accounts/db.d.ts.map +1 -0
  4. package/bin/accounts/db.js +68 -0
  5. package/bin/accounts/db.js.map +1 -0
  6. package/bin/accounts/index.d.ts +348 -0
  7. package/bin/accounts/index.d.ts.map +1 -0
  8. package/bin/accounts/index.js +681 -0
  9. package/bin/accounts/index.js.map +1 -0
  10. package/bin/accounts/oauth.d.ts +129 -0
  11. package/bin/accounts/oauth.d.ts.map +1 -0
  12. package/bin/accounts/oauth.js +220 -0
  13. package/bin/accounts/oauth.js.map +1 -0
  14. package/bin/accounts/schema.d.ts +319 -0
  15. package/bin/accounts/schema.d.ts.map +1 -0
  16. package/bin/accounts/schema.js +72 -0
  17. package/bin/accounts/schema.js.map +1 -0
  18. package/bin/balance/index.d.ts +7 -0
  19. package/bin/balance/index.d.ts.map +1 -0
  20. package/bin/balance/index.js +6 -0
  21. package/bin/balance/index.js.map +1 -0
  22. package/bin/balance/raw.d.ts +20 -0
  23. package/bin/balance/raw.d.ts.map +1 -0
  24. package/bin/balance/raw.js +75 -0
  25. package/bin/balance/raw.js.map +1 -0
  26. package/bin/balance/routes.d.ts +14 -0
  27. package/bin/balance/routes.d.ts.map +1 -0
  28. package/bin/balance/routes.js +166 -0
  29. package/bin/balance/routes.js.map +1 -0
  30. package/bin/balance/schema.d.ts +764 -0
  31. package/bin/balance/schema.d.ts.map +1 -0
  32. package/bin/balance/schema.js +185 -0
  33. package/bin/balance/schema.js.map +1 -0
  34. package/bin/balance/service.d.ts +880 -0
  35. package/bin/balance/service.d.ts.map +1 -0
  36. package/bin/balance/service.js +557 -0
  37. package/bin/balance/service.js.map +1 -0
  38. package/bin/balance/types.d.ts +326 -0
  39. package/bin/balance/types.d.ts.map +1 -0
  40. package/bin/balance/types.js +10 -0
  41. package/bin/balance/types.js.map +1 -0
  42. package/bin/balance/utils.d.ts +91 -0
  43. package/bin/balance/utils.d.ts.map +1 -0
  44. package/bin/balance/utils.js +231 -0
  45. package/bin/balance/utils.js.map +1 -0
  46. package/bin/index.d.ts +22 -0
  47. package/bin/index.d.ts.map +1 -0
  48. package/bin/index.js +16 -0
  49. package/bin/index.js.map +1 -0
  50. package/bin/payment/index.d.ts +19 -0
  51. package/bin/payment/index.d.ts.map +1 -0
  52. package/bin/payment/index.js +63 -0
  53. package/bin/payment/index.js.map +1 -0
  54. package/bin/payment/types.d.ts +107 -0
  55. package/bin/payment/types.d.ts.map +1 -0
  56. package/bin/payment/types.js +10 -0
  57. package/bin/payment/types.js.map +1 -0
  58. package/bin/payment-stripe/index.d.ts +17 -0
  59. package/bin/payment-stripe/index.d.ts.map +1 -0
  60. package/bin/payment-stripe/index.js +619 -0
  61. package/bin/payment-stripe/index.js.map +1 -0
  62. package/bin/payment-stripe/schema.d.ts +378 -0
  63. package/bin/payment-stripe/schema.d.ts.map +1 -0
  64. package/bin/payment-stripe/schema.js +47 -0
  65. package/bin/payment-stripe/schema.js.map +1 -0
  66. package/bin/payment-stripe/stripe.d.ts +38 -0
  67. package/bin/payment-stripe/stripe.d.ts.map +1 -0
  68. package/bin/payment-stripe/stripe.js +129 -0
  69. package/bin/payment-stripe/stripe.js.map +1 -0
  70. package/bin/payment-stripe/types.d.ts +331 -0
  71. package/bin/payment-stripe/types.d.ts.map +1 -0
  72. package/bin/payment-stripe/types.js +10 -0
  73. package/bin/payment-stripe/types.js.map +1 -0
  74. package/bin/usage/index.d.ts +177 -0
  75. package/bin/usage/index.d.ts.map +1 -0
  76. package/bin/usage/index.js +120 -0
  77. package/bin/usage/index.js.map +1 -0
  78. package/package.json +60 -0
@@ -0,0 +1,319 @@
1
+ /**
2
+ * Accounts 服务数据库 schema 模块。
3
+ *
4
+ * 负责定义服务自身维护的业务资料表:
5
+ * - user_profile:给产品层直接展示的用户资料
6
+ * - oauth_state:CLI / 轮询式 OAuth 流程的临时 state
7
+ */
8
+ /**
9
+ * 用户资料表名。
10
+ */
11
+ export declare const USER_PROFILE_TABLE = "auth_profiles";
12
+ /**
13
+ * Accounts 服务 OAuth state 表名。
14
+ */
15
+ export declare const ACCOUNTS_OAUTH_STATE_TABLE = "service_accounts_oauth_states";
16
+ /**
17
+ * 产品层使用的用户资料。
18
+ */
19
+ export interface UserProfileRow extends Record<string, unknown> {
20
+ /**
21
+ * 对应 better-auth `user.id`。
22
+ */
23
+ user_id: string;
24
+ /**
25
+ * 当前资料使用的主邮箱。
26
+ */
27
+ email: string;
28
+ /**
29
+ * 产品层展示名。
30
+ */
31
+ display_name: string;
32
+ /**
33
+ * 产品层头像 URL。
34
+ */
35
+ avatar_url: string;
36
+ /**
37
+ * 用户简介。
38
+ *
39
+ * 当前默认保留为空串,后续可给业务层编辑。
40
+ */
41
+ bio: string;
42
+ /**
43
+ * 首次创建时间。
44
+ */
45
+ created_at: string;
46
+ /**
47
+ * 最近更新时间。
48
+ */
49
+ updated_at: string;
50
+ }
51
+ /**
52
+ * OAuth 轮询 state 记录。
53
+ */
54
+ export interface AccountsOAuthStateRow extends Record<string, unknown> {
55
+ /**
56
+ * OAuth state。
57
+ */
58
+ state: string;
59
+ /**
60
+ * 登录成功后要签发到哪个 product。
61
+ */
62
+ product_id: string;
63
+ /**
64
+ * 第三方 provider 标识。
65
+ */
66
+ provider: string;
67
+ /**
68
+ * 完成登录后回填的 InfraRuntime user_token。
69
+ */
70
+ user_token: string;
71
+ /**
72
+ * state 创建时间戳(毫秒)。
73
+ */
74
+ created_at: number;
75
+ }
76
+ /**
77
+ * 用户资料表。
78
+ */
79
+ export declare const userProfiles: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
80
+ name: "auth_profiles";
81
+ schema: undefined;
82
+ columns: {
83
+ user_id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
84
+ name: "user_id";
85
+ tableName: "auth_profiles";
86
+ dataType: "string";
87
+ columnType: "SQLiteText";
88
+ data: string;
89
+ driverParam: string;
90
+ notNull: true;
91
+ hasDefault: false;
92
+ isPrimaryKey: true;
93
+ isAutoincrement: false;
94
+ hasRuntimeDefault: false;
95
+ enumValues: [string, ...string[]];
96
+ baseColumn: never;
97
+ identity: undefined;
98
+ generated: undefined;
99
+ }, {}, {
100
+ length: number | undefined;
101
+ }>;
102
+ email: import("drizzle-orm/sqlite-core").SQLiteColumn<{
103
+ name: "email";
104
+ tableName: "auth_profiles";
105
+ dataType: "string";
106
+ columnType: "SQLiteText";
107
+ data: string;
108
+ driverParam: string;
109
+ notNull: true;
110
+ hasDefault: false;
111
+ isPrimaryKey: false;
112
+ isAutoincrement: false;
113
+ hasRuntimeDefault: false;
114
+ enumValues: [string, ...string[]];
115
+ baseColumn: never;
116
+ identity: undefined;
117
+ generated: undefined;
118
+ }, {}, {
119
+ length: number | undefined;
120
+ }>;
121
+ display_name: import("drizzle-orm/sqlite-core").SQLiteColumn<{
122
+ name: "display_name";
123
+ tableName: "auth_profiles";
124
+ dataType: "string";
125
+ columnType: "SQLiteText";
126
+ data: string;
127
+ driverParam: string;
128
+ notNull: true;
129
+ hasDefault: false;
130
+ isPrimaryKey: false;
131
+ isAutoincrement: false;
132
+ hasRuntimeDefault: false;
133
+ enumValues: [string, ...string[]];
134
+ baseColumn: never;
135
+ identity: undefined;
136
+ generated: undefined;
137
+ }, {}, {
138
+ length: number | undefined;
139
+ }>;
140
+ avatar_url: import("drizzle-orm/sqlite-core").SQLiteColumn<{
141
+ name: "avatar_url";
142
+ tableName: "auth_profiles";
143
+ dataType: "string";
144
+ columnType: "SQLiteText";
145
+ data: string;
146
+ driverParam: string;
147
+ notNull: true;
148
+ hasDefault: false;
149
+ isPrimaryKey: false;
150
+ isAutoincrement: false;
151
+ hasRuntimeDefault: false;
152
+ enumValues: [string, ...string[]];
153
+ baseColumn: never;
154
+ identity: undefined;
155
+ generated: undefined;
156
+ }, {}, {
157
+ length: number | undefined;
158
+ }>;
159
+ bio: import("drizzle-orm/sqlite-core").SQLiteColumn<{
160
+ name: "bio";
161
+ tableName: "auth_profiles";
162
+ dataType: "string";
163
+ columnType: "SQLiteText";
164
+ data: string;
165
+ driverParam: string;
166
+ notNull: true;
167
+ hasDefault: false;
168
+ isPrimaryKey: false;
169
+ isAutoincrement: false;
170
+ hasRuntimeDefault: false;
171
+ enumValues: [string, ...string[]];
172
+ baseColumn: never;
173
+ identity: undefined;
174
+ generated: undefined;
175
+ }, {}, {
176
+ length: number | undefined;
177
+ }>;
178
+ created_at: import("drizzle-orm/sqlite-core").SQLiteColumn<{
179
+ name: "created_at";
180
+ tableName: "auth_profiles";
181
+ dataType: "string";
182
+ columnType: "SQLiteText";
183
+ data: string;
184
+ driverParam: string;
185
+ notNull: true;
186
+ hasDefault: false;
187
+ isPrimaryKey: false;
188
+ isAutoincrement: false;
189
+ hasRuntimeDefault: false;
190
+ enumValues: [string, ...string[]];
191
+ baseColumn: never;
192
+ identity: undefined;
193
+ generated: undefined;
194
+ }, {}, {
195
+ length: number | undefined;
196
+ }>;
197
+ updated_at: import("drizzle-orm/sqlite-core").SQLiteColumn<{
198
+ name: "updated_at";
199
+ tableName: "auth_profiles";
200
+ dataType: "string";
201
+ columnType: "SQLiteText";
202
+ data: string;
203
+ driverParam: string;
204
+ notNull: true;
205
+ hasDefault: false;
206
+ isPrimaryKey: false;
207
+ isAutoincrement: false;
208
+ hasRuntimeDefault: false;
209
+ enumValues: [string, ...string[]];
210
+ baseColumn: never;
211
+ identity: undefined;
212
+ generated: undefined;
213
+ }, {}, {
214
+ length: number | undefined;
215
+ }>;
216
+ };
217
+ dialect: "sqlite";
218
+ }>;
219
+ export declare const accountsOAuthStates: import("drizzle-orm/sqlite-core").SQLiteTableWithColumns<{
220
+ name: "service_accounts_oauth_states";
221
+ schema: undefined;
222
+ columns: {
223
+ state: import("drizzle-orm/sqlite-core").SQLiteColumn<{
224
+ name: "state";
225
+ tableName: "service_accounts_oauth_states";
226
+ dataType: "string";
227
+ columnType: "SQLiteText";
228
+ data: string;
229
+ driverParam: string;
230
+ notNull: true;
231
+ hasDefault: false;
232
+ isPrimaryKey: true;
233
+ isAutoincrement: false;
234
+ hasRuntimeDefault: false;
235
+ enumValues: [string, ...string[]];
236
+ baseColumn: never;
237
+ identity: undefined;
238
+ generated: undefined;
239
+ }, {}, {
240
+ length: number | undefined;
241
+ }>;
242
+ product_id: import("drizzle-orm/sqlite-core").SQLiteColumn<{
243
+ name: "product_id";
244
+ tableName: "service_accounts_oauth_states";
245
+ dataType: "string";
246
+ columnType: "SQLiteText";
247
+ data: string;
248
+ driverParam: string;
249
+ notNull: true;
250
+ hasDefault: false;
251
+ isPrimaryKey: false;
252
+ isAutoincrement: false;
253
+ hasRuntimeDefault: false;
254
+ enumValues: [string, ...string[]];
255
+ baseColumn: never;
256
+ identity: undefined;
257
+ generated: undefined;
258
+ }, {}, {
259
+ length: number | undefined;
260
+ }>;
261
+ provider: import("drizzle-orm/sqlite-core").SQLiteColumn<{
262
+ name: "provider";
263
+ tableName: "service_accounts_oauth_states";
264
+ dataType: "string";
265
+ columnType: "SQLiteText";
266
+ data: string;
267
+ driverParam: string;
268
+ notNull: true;
269
+ hasDefault: false;
270
+ isPrimaryKey: false;
271
+ isAutoincrement: false;
272
+ hasRuntimeDefault: false;
273
+ enumValues: [string, ...string[]];
274
+ baseColumn: never;
275
+ identity: undefined;
276
+ generated: undefined;
277
+ }, {}, {
278
+ length: number | undefined;
279
+ }>;
280
+ user_token: import("drizzle-orm/sqlite-core").SQLiteColumn<{
281
+ name: "user_token";
282
+ tableName: "service_accounts_oauth_states";
283
+ dataType: "string";
284
+ columnType: "SQLiteText";
285
+ data: string;
286
+ driverParam: string;
287
+ notNull: true;
288
+ hasDefault: false;
289
+ isPrimaryKey: false;
290
+ isAutoincrement: false;
291
+ hasRuntimeDefault: false;
292
+ enumValues: [string, ...string[]];
293
+ baseColumn: never;
294
+ identity: undefined;
295
+ generated: undefined;
296
+ }, {}, {
297
+ length: number | undefined;
298
+ }>;
299
+ created_at: import("drizzle-orm/sqlite-core").SQLiteColumn<{
300
+ name: "created_at";
301
+ tableName: "service_accounts_oauth_states";
302
+ dataType: "number";
303
+ columnType: "SQLiteInteger";
304
+ data: number;
305
+ driverParam: number;
306
+ notNull: true;
307
+ hasDefault: false;
308
+ isPrimaryKey: false;
309
+ isAutoincrement: false;
310
+ hasRuntimeDefault: false;
311
+ enumValues: undefined;
312
+ baseColumn: never;
313
+ identity: undefined;
314
+ generated: undefined;
315
+ }, {}, {}>;
316
+ };
317
+ dialect: "sqlite";
318
+ }>;
319
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/accounts/schema.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;GAEG;AACH,eAAO,MAAM,kBAAkB,kBAAkB,CAAC;AAElD;;GAEG;AACH,eAAO,MAAM,0BAA0B,kCAAkC,CAAC;AAE1E;;GAEG;AACH,MAAM,WAAW,cAAe,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC7D;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;OAIG;IACH,GAAG,EAAE,MAAM,CAAC;IAEZ;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACpE;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmCvB,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyB9B,CAAC"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Accounts 服务数据库 schema 模块。
3
+ *
4
+ * 负责定义服务自身维护的业务资料表:
5
+ * - user_profile:给产品层直接展示的用户资料
6
+ * - oauth_state:CLI / 轮询式 OAuth 流程的临时 state
7
+ */
8
+ import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
9
+ /**
10
+ * 用户资料表名。
11
+ */
12
+ export const USER_PROFILE_TABLE = "auth_profiles";
13
+ /**
14
+ * Accounts 服务 OAuth state 表名。
15
+ */
16
+ export const ACCOUNTS_OAUTH_STATE_TABLE = "service_accounts_oauth_states";
17
+ /**
18
+ * 用户资料表。
19
+ */
20
+ export const userProfiles = sqliteTable(USER_PROFILE_TABLE, {
21
+ /**
22
+ * 对应 better-auth `user.id`。
23
+ */
24
+ user_id: text("user_id").primaryKey(),
25
+ /**
26
+ * 当前主邮箱。
27
+ */
28
+ email: text("email").notNull(),
29
+ /**
30
+ * 展示名。
31
+ */
32
+ display_name: text("display_name").notNull(),
33
+ /**
34
+ * 头像 URL。
35
+ */
36
+ avatar_url: text("avatar_url").notNull(),
37
+ /**
38
+ * 简介。
39
+ */
40
+ bio: text("bio").notNull(),
41
+ /**
42
+ * 创建时间。
43
+ */
44
+ created_at: text("created_at").notNull(),
45
+ /**
46
+ * 更新时间。
47
+ */
48
+ updated_at: text("updated_at").notNull(),
49
+ });
50
+ export const accountsOAuthStates = sqliteTable(ACCOUNTS_OAUTH_STATE_TABLE, {
51
+ /**
52
+ * OAuth state。
53
+ */
54
+ state: text("state").primaryKey(),
55
+ /**
56
+ * 登录成功后要签发到哪个 product。
57
+ */
58
+ product_id: text("product_id").notNull(),
59
+ /**
60
+ * provider 标识。
61
+ */
62
+ provider: text("provider").notNull(),
63
+ /**
64
+ * 完成登录后回填的 InfraRuntime user_token。
65
+ */
66
+ user_token: text("user_token").notNull(),
67
+ /**
68
+ * 创建时间戳(毫秒)。
69
+ */
70
+ created_at: integer("created_at").notNull(),
71
+ });
72
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/accounts/schema.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AAErE;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,eAAe,CAAC;AAElD;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,+BAA+B,CAAC;AA0E1E;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,WAAW,CAAC,kBAAkB,EAAE;IAC1D;;OAEG;IACH,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE;IAErC;;OAEG;IACH,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE;IAE9B;;OAEG;IACH,YAAY,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC,OAAO,EAAE;IAE5C;;OAEG;IACH,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE;IAExC;;OAEG;IACH,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE;IAE1B;;OAEG;IACH,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE;IAExC;;OAEG;IACH,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE;CACzC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG,WAAW,CAAC,0BAA0B,EAAE;IACzE;;OAEG;IACH,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE;IAEjC;;OAEG;IACH,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE;IAExC;;OAEG;IACH,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE;IAEpC;;OAEG;IACH,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE;IAExC;;OAEG;IACH,UAAU,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE;CAC5C,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * balance 服务子模块公共入口。
3
+ */
4
+ export { BalanceService, balanceService } from "./service.js";
5
+ export { balanceAccounts, balanceLedger, balanceRedeemCodes, balanceTopups, } from "./schema.js";
6
+ export type { BalanceAccount, BalanceCreateRedeemCodeInput, BalanceExtra, BalanceHistoryQuery, BalanceLedgerEntry, BalanceLedgerKind, BalanceServiceOptions, BalanceRedeemCode, BalanceRedeemCodeIssueResult, BalanceRedeemCodeQuery, BalanceRedeemCodeRedeemResult, BalanceRedeemCodeStatus, BalanceTopup, BalanceTopupQuery, BalanceTopupStatus, } from "./types.js";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/balance/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EACL,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,aAAa,GACd,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,cAAc,EACd,4BAA4B,EAC5B,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EACrB,iBAAiB,EACjB,4BAA4B,EAC5B,sBAAsB,EACtB,6BAA6B,EAC7B,uBAAuB,EACvB,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,YAAY,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * balance 服务子模块公共入口。
3
+ */
4
+ export { BalanceService, balanceService } from "./service.js";
5
+ export { balanceAccounts, balanceLedger, balanceRedeemCodes, balanceTopups, } from "./schema.js";
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/balance/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EACL,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,aAAa,GACd,MAAM,aAAa,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Balance 服务底层数据库访问工具。
3
+ *
4
+ * 关键说明(中文)
5
+ * - 同时兼容 sqlite 与 D1 的 prepare 接口
6
+ * - 这里统一封装 run / first / all,业务逻辑不再感知方言差异
7
+ */
8
+ /**
9
+ * 执行写操作。
10
+ */
11
+ export declare function rawRun(raw: unknown, sql: string, params: unknown[]): Promise<number>;
12
+ /**
13
+ * 读取单行记录。
14
+ */
15
+ export declare function rawFirst<TRow extends Record<string, unknown>>(raw: unknown, sql: string, params: unknown[]): Promise<TRow | undefined>;
16
+ /**
17
+ * 读取多行记录。
18
+ */
19
+ export declare function rawAll<TRow extends Record<string, unknown>>(raw: unknown, sql: string, params: unknown[]): Promise<TRow[]>;
20
+ //# sourceMappingURL=raw.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"raw.d.ts","sourceRoot":"","sources":["../../src/balance/raw.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAoCH;;GAEG;AACH,wBAAsB,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAW1F;AAED;;GAEG;AACH,wBAAsB,QAAQ,CAAC,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjE,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,OAAO,EAAE,GAChB,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,CAgB3B;AAED;;GAEG;AACH,wBAAsB,MAAM,CAAC,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/D,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,OAAO,EAAE,GAChB,OAAO,CAAC,IAAI,EAAE,CAAC,CAiBjB"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Balance 服务底层数据库访问工具。
3
+ *
4
+ * 关键说明(中文)
5
+ * - 同时兼容 sqlite 与 D1 的 prepare 接口
6
+ * - 这里统一封装 run / first / all,业务逻辑不再感知方言差异
7
+ */
8
+ function prepareRawStatement(raw, sql, params) {
9
+ const prepare = raw.prepare;
10
+ if (typeof prepare !== "function") {
11
+ throw new Error("balance service requires a raw database with prepare()");
12
+ }
13
+ const statement = prepare.call(raw, sql);
14
+ if (typeof statement.bind === "function" && typeof statement.get !== "function") {
15
+ return {
16
+ kind: "d1",
17
+ statement: statement.bind(...params),
18
+ params: [],
19
+ };
20
+ }
21
+ return {
22
+ kind: "sqlite",
23
+ statement,
24
+ params,
25
+ };
26
+ }
27
+ /**
28
+ * 执行写操作。
29
+ */
30
+ export async function rawRun(raw, sql, params) {
31
+ const prepared = prepareRawStatement(raw, sql, params);
32
+ if (typeof prepared.statement.run !== "function") {
33
+ throw new Error("Prepared statement does not support run()");
34
+ }
35
+ const result = await prepared.statement.run(...prepared.params);
36
+ return Number(result?.changes ?? result?.meta?.changes ?? 0);
37
+ }
38
+ /**
39
+ * 读取单行记录。
40
+ */
41
+ export async function rawFirst(raw, sql, params) {
42
+ const prepared = prepareRawStatement(raw, sql, params);
43
+ if (prepared.kind === "d1") {
44
+ if (typeof prepared.statement.first !== "function") {
45
+ throw new Error("Prepared statement does not support first()");
46
+ }
47
+ const result = await prepared.statement.first();
48
+ return result ? result : undefined;
49
+ }
50
+ if (typeof prepared.statement.get !== "function") {
51
+ throw new Error("Prepared statement does not support get()");
52
+ }
53
+ const result = prepared.statement.get(...prepared.params);
54
+ return result ? result : undefined;
55
+ }
56
+ /**
57
+ * 读取多行记录。
58
+ */
59
+ export async function rawAll(raw, sql, params) {
60
+ const prepared = prepareRawStatement(raw, sql, params);
61
+ if (prepared.kind === "d1") {
62
+ if (typeof prepared.statement.all !== "function") {
63
+ throw new Error("Prepared statement does not support all()");
64
+ }
65
+ const result = await prepared.statement.all();
66
+ const rows = result?.results;
67
+ return Array.isArray(rows) ? rows : [];
68
+ }
69
+ if (typeof prepared.statement.all !== "function") {
70
+ throw new Error("Prepared statement does not support all()");
71
+ }
72
+ const result = prepared.statement.all(...prepared.params);
73
+ return Array.isArray(result) ? result : [];
74
+ }
75
+ //# sourceMappingURL=raw.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"raw.js","sourceRoot":"","sources":["../../src/balance/raw.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAUH,SAAS,mBAAmB,CAC1B,GAAY,EACZ,GAAW,EACX,MAAiB;IAEjB,MAAM,OAAO,GAAI,GAAqD,CAAC,OAAO,CAAC;IAC/E,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC5E,CAAC;IAED,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,G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Q,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC1D,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;AACvD,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Balance 服务 HTTP 路由装配模块。
3
+ *
4
+ * 关键说明(中文)
5
+ * - 这里只负责把公开 action 映射到 HTTP 路由
6
+ * - 余额读写、充值单和兑换码状态变更仍然收敛在 BalanceService 内部
7
+ */
8
+ import type { ServiceInstallContext } from "@downcity/infra";
9
+ import type { BalanceService } from "./service.js";
10
+ /**
11
+ * 注册 Balance 服务的 HTTP 路由。
12
+ */
13
+ export declare function registerBalanceRoutes(service: BalanceService, ctx: ServiceInstallContext): void;
14
+ //# sourceMappingURL=routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/balance/routes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAuB,MAAM,iBAAiB,CAAC;AAClF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAkEnD;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE,qBAAqB,GAAG,IAAI,CAoK/F"}