@longzai-intelligence-npm-registry/core 0.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.
@@ -0,0 +1,791 @@
1
+ import "./rolldown-runtime-BqT_7tdF.js";
2
+ import * as z from "zod";
3
+ import { DomainError } from "@longzai-intelligence-error/core";
4
+ //#region src/contracts/package.schema.d.ts
5
+ /**
6
+ * 本地包摘要 DTO(引擎 listPackages 条目;`GET /api/packages` 数据)
7
+ */
8
+ declare const PackageSummarySchema: z.ZodObject<{
9
+ name: z.ZodString;
10
+ versionCount: z.ZodNumber;
11
+ latest: z.ZodOptional<z.ZodString>;
12
+ modified: z.ZodOptional<z.ZodString>;
13
+ }, z.core.$strip>;
14
+ /**
15
+ * 本地包详情 DTO(`GET /api/packages/:name` 数据)
16
+ */
17
+ declare const PackageDetailSchema: z.ZodObject<{
18
+ name: z.ZodString;
19
+ versionCount: z.ZodNumber;
20
+ latest: z.ZodOptional<z.ZodString>;
21
+ modified: z.ZodOptional<z.ZodString>;
22
+ distTags: z.ZodRecord<z.ZodString, z.ZodString>;
23
+ versions: z.ZodArray<z.ZodString>;
24
+ }, z.core.$strip>;
25
+ /**
26
+ * 本地包详情 DTO 形态
27
+ */
28
+ type PackageDetail = z.infer<typeof PackageDetailSchema>;
29
+ /**
30
+ * 本地包摘要 DTO 形态
31
+ */
32
+ type PackageSummary = z.infer<typeof PackageSummarySchema>;
33
+ //#endregion
34
+ //#region src/contracts/protocol.schema.d.ts
35
+ /**
36
+ * npm 包名合法形态(scoped `@scope/name` 或 unscoped;小写字母开头,允许 . _ - 与数字)
37
+ */
38
+ declare const PACKAGE_NAME_PATTERN: RegExp;
39
+ /**
40
+ * 语义化版本(宽松形态:允许 prerelease/build 后缀,npm publish 全量接受)
41
+ */
42
+ declare const SEMVER_PATTERN: RegExp;
43
+ /**
44
+ * dist-tag 合法形态(npm 限制:不可含 ~'(){} 与 URL 不安全字符;此处取宽松子集)
45
+ */
46
+ declare const DIST_TAG_PATTERN: RegExp;
47
+ /**
48
+ * couchdb 用户文档 id 前缀(npm login/adduser 协议约定)
49
+ */
50
+ declare const COUCHDB_USER_ID_PREFIX = "org.couchdb.user:";
51
+ /**
52
+ * 包名标识(scoped 形态 `%2F` 转义在路由层解码后进入本契约)
53
+ */
54
+ declare const PackageIdentifierSchema: z.ZodString;
55
+ /**
56
+ * 语义化版本字符串
57
+ */
58
+ declare const SemverSchema: z.ZodString;
59
+ /**
60
+ * 版本 dist 元数据(tarball 为服务时动态注入的 wire 字段,落盘不持久化)
61
+ */
62
+ declare const DistMetaSchema: z.ZodObject<{
63
+ shasum: z.ZodOptional<z.ZodString>;
64
+ integrity: z.ZodOptional<z.ZodString>;
65
+ tarball: z.ZodOptional<z.ZodString>;
66
+ fileCount: z.ZodOptional<z.ZodNumber>;
67
+ unpackedSize: z.ZodOptional<z.ZodNumber>;
68
+ }, z.core.$strip>;
69
+ /**
70
+ * 单版本 manifest(npm packument `versions[v]` 条目;客户端 manifest 字段全量透传,此处只约束必需键)
71
+ */
72
+ declare const VersionManifestSchema: z.ZodObject<{
73
+ name: z.ZodString;
74
+ version: z.ZodString;
75
+ dist: z.ZodObject<{
76
+ shasum: z.ZodOptional<z.ZodString>;
77
+ integrity: z.ZodOptional<z.ZodString>;
78
+ tarball: z.ZodOptional<z.ZodString>;
79
+ fileCount: z.ZodOptional<z.ZodNumber>;
80
+ unpackedSize: z.ZodOptional<z.ZodNumber>;
81
+ }, z.core.$strip>;
82
+ }, z.core.$loose>;
83
+ /**
84
+ * dist-tag 映射(tag → 版本号)
85
+ */
86
+ declare const DistTagMapSchema: z.ZodRecord<z.ZodString, z.ZodString>;
87
+ /**
88
+ * packument(`GET /:package` 响应/落盘形状;落盘不含 dist.tarball 绝对地址)
89
+ */
90
+ declare const PackumentSchema: z.ZodObject<{
91
+ _id: z.ZodString;
92
+ _rev: z.ZodOptional<z.ZodString>;
93
+ name: z.ZodString;
94
+ description: z.ZodOptional<z.ZodString>;
95
+ 'dist-tags': z.ZodRecord<z.ZodString, z.ZodString>;
96
+ versions: z.ZodRecord<z.ZodString, z.ZodObject<{
97
+ name: z.ZodString;
98
+ version: z.ZodString;
99
+ dist: z.ZodObject<{
100
+ shasum: z.ZodOptional<z.ZodString>;
101
+ integrity: z.ZodOptional<z.ZodString>;
102
+ tarball: z.ZodOptional<z.ZodString>;
103
+ fileCount: z.ZodOptional<z.ZodNumber>;
104
+ unpackedSize: z.ZodOptional<z.ZodNumber>;
105
+ }, z.core.$strip>;
106
+ }, z.core.$loose>>;
107
+ time: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
108
+ maintainers: z.ZodOptional<z.ZodArray<z.ZodObject<{
109
+ name: z.ZodString;
110
+ email: z.ZodOptional<z.ZodString>;
111
+ }, z.core.$loose>>>;
112
+ readme: z.ZodOptional<z.ZodString>;
113
+ }, z.core.$loose>;
114
+ /**
115
+ * publish 附件(`_attachments` 条目;data 为 base64 tarball)
116
+ */
117
+ declare const PublishAttachmentSchema: z.ZodObject<{
118
+ content_type: z.ZodString;
119
+ data: z.ZodString;
120
+ length: z.ZodNumber;
121
+ }, z.core.$strip>;
122
+ /**
123
+ * publish 请求载荷(`PUT /:package` 请求体;versions 仅含本次新版本)
124
+ */
125
+ declare const PublishPayloadSchema: z.ZodObject<{
126
+ _id: z.ZodOptional<z.ZodString>;
127
+ name: z.ZodString;
128
+ description: z.ZodOptional<z.ZodString>;
129
+ 'dist-tags': z.ZodRecord<z.ZodString, z.ZodString>;
130
+ versions: z.ZodRecord<z.ZodString, z.ZodObject<{
131
+ name: z.ZodString;
132
+ version: z.ZodString;
133
+ dist: z.ZodObject<{
134
+ shasum: z.ZodOptional<z.ZodString>;
135
+ integrity: z.ZodOptional<z.ZodString>;
136
+ tarball: z.ZodOptional<z.ZodString>;
137
+ fileCount: z.ZodOptional<z.ZodNumber>;
138
+ unpackedSize: z.ZodOptional<z.ZodNumber>;
139
+ }, z.core.$strip>;
140
+ }, z.core.$loose>>;
141
+ access: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
142
+ public: "public";
143
+ restricted: "restricted";
144
+ }>>>;
145
+ readme: z.ZodOptional<z.ZodString>;
146
+ _attachments: z.ZodRecord<z.ZodString, z.ZodObject<{
147
+ content_type: z.ZodString;
148
+ data: z.ZodString;
149
+ length: z.ZodNumber;
150
+ }, z.core.$strip>>;
151
+ maintainers: z.ZodOptional<z.ZodArray<z.ZodObject<{
152
+ name: z.ZodString;
153
+ email: z.ZodOptional<z.ZodString>;
154
+ }, z.core.$loose>>>;
155
+ }, z.core.$loose>;
156
+ /**
157
+ * publish 成功响应(npm 约定形状)
158
+ */
159
+ declare const PublishResponseSchema: z.ZodObject<{
160
+ ok: z.ZodLiteral<true>;
161
+ rev: z.ZodString;
162
+ id: z.ZodOptional<z.ZodString>;
163
+ }, z.core.$strip>;
164
+ /**
165
+ * whoami 响应(`GET /-/whoami`)
166
+ */
167
+ declare const WhoamiResponseSchema: z.ZodObject<{
168
+ username: z.ZodString;
169
+ }, z.core.$strip>;
170
+ /**
171
+ * couchdb 用户文档载荷(`PUT /-/user/org.couchdb.user::username` 请求体,npm adduser/login)
172
+ */
173
+ declare const CouchUserPayloadSchema: z.ZodObject<{
174
+ _id: z.ZodOptional<z.ZodString>;
175
+ name: z.ZodString;
176
+ password: z.ZodString;
177
+ email: z.ZodOptional<z.ZodEmail>;
178
+ type: z.ZodOptional<z.ZodLiteral<"user">>;
179
+ roles: z.ZodOptional<z.ZodArray<z.ZodString>>;
180
+ date: z.ZodOptional<z.ZodString>;
181
+ }, z.core.$loose>;
182
+ /**
183
+ * npm 协议错误响应(`{"error":"…"}` 裸形状)
184
+ */
185
+ declare const NpmErrorResponseSchema: z.ZodObject<{
186
+ error: z.ZodString;
187
+ }, z.core.$strip>;
188
+ /**
189
+ * couchdb 用户文档载荷形态
190
+ */
191
+ type CouchUserPayload = z.infer<typeof CouchUserPayloadSchema>;
192
+ /**
193
+ * 版本 dist 元数据形态
194
+ */
195
+ type DistMeta = z.infer<typeof DistMetaSchema>;
196
+ /**
197
+ * dist-tag 映射形态
198
+ */
199
+ type DistTagMap = z.infer<typeof DistTagMapSchema>;
200
+ /**
201
+ * npm 协议错误响应形态
202
+ */
203
+ type NpmErrorResponse = z.infer<typeof NpmErrorResponseSchema>;
204
+ /**
205
+ * packument 形态
206
+ */
207
+ type Packument = z.infer<typeof PackumentSchema>;
208
+ /**
209
+ * 包名标识形态
210
+ */
211
+ type PackageIdentifier = z.infer<typeof PackageIdentifierSchema>;
212
+ /**
213
+ * publish 附件形态
214
+ */
215
+ type PublishAttachment = z.infer<typeof PublishAttachmentSchema>;
216
+ /**
217
+ * publish 载荷形态
218
+ */
219
+ type PublishPayload = z.infer<typeof PublishPayloadSchema>;
220
+ /**
221
+ * publish 成功响应形态
222
+ */
223
+ type PublishResponse = z.infer<typeof PublishResponseSchema>;
224
+ /**
225
+ * 语义化版本形态
226
+ */
227
+ type Semver = z.infer<typeof SemverSchema>;
228
+ /**
229
+ * 版本 manifest 形态
230
+ */
231
+ type VersionManifest = z.infer<typeof VersionManifestSchema>;
232
+ /**
233
+ * whoami 响应形态
234
+ */
235
+ type WhoamiResponse = z.infer<typeof WhoamiResponseSchema>;
236
+ //#endregion
237
+ //#region src/contracts/store.schema.d.ts
238
+ /**
239
+ * 本地 token 前缀(签发明文形态 `lzi_local_<随机>`;存储只落 sha256 哈希)
240
+ */
241
+ declare const TOKEN_PREFIX = "lzi_local_";
242
+ /**
243
+ * auth store 结构版本(结构不兼容演进时递增并迁移)
244
+ */
245
+ declare const AUTH_STORE_VERSION = 1;
246
+ /**
247
+ * 口令哈希记录(sha256(salt + password) 盐渍单轮——本机回环单用户威胁模型下的务实取舍)
248
+ */
249
+ declare const PasswordRecordSchema: z.ZodObject<{
250
+ salt: z.ZodString;
251
+ hash: z.ZodString;
252
+ }, z.core.$strip>;
253
+ /**
254
+ * token 记录(明文永不落盘;id 为独立随机 8 位十六进制供人识别与吊销定位)
255
+ */
256
+ declare const TokenRecordSchema: z.ZodObject<{
257
+ id: z.ZodString;
258
+ username: z.ZodString;
259
+ tokenHash: z.ZodString;
260
+ note: z.ZodOptional<z.ZodString>;
261
+ createdAt: z.ZodString;
262
+ revokedAt: z.ZodOptional<z.ZodString>;
263
+ }, z.core.$strip>;
264
+ /**
265
+ * auth store(`<DATA_ROOT>/auth.json` 落盘形状)
266
+ */
267
+ declare const AuthStoreSchema: z.ZodObject<{
268
+ version: z.ZodLiteral<1>;
269
+ users: z.ZodRecord<z.ZodString, z.ZodObject<{
270
+ password: z.ZodObject<{
271
+ salt: z.ZodString;
272
+ hash: z.ZodString;
273
+ }, z.core.$strip>;
274
+ }, z.core.$strip>>;
275
+ tokens: z.ZodArray<z.ZodObject<{
276
+ id: z.ZodString;
277
+ username: z.ZodString;
278
+ tokenHash: z.ZodString;
279
+ note: z.ZodOptional<z.ZodString>;
280
+ createdAt: z.ZodString;
281
+ revokedAt: z.ZodOptional<z.ZodString>;
282
+ }, z.core.$strip>>;
283
+ }, z.core.$strip>;
284
+ /**
285
+ * token 签发结果 DTO(明文仅此一次返回)
286
+ */
287
+ declare const TokenCreateInfoSchema: z.ZodObject<{
288
+ id: z.ZodString;
289
+ token: z.ZodString;
290
+ note: z.ZodOptional<z.ZodString>;
291
+ createdAt: z.ZodString;
292
+ }, z.core.$strip>;
293
+ /**
294
+ * token 信息 DTO(不含明文)
295
+ */
296
+ declare const TokenInfoSchema: z.ZodObject<{
297
+ id: z.ZodString;
298
+ note: z.ZodOptional<z.ZodString>;
299
+ createdAt: z.ZodString;
300
+ revoked: z.ZodBoolean;
301
+ }, z.core.$strip>;
302
+ /**
303
+ * auth store 形态
304
+ */
305
+ type AuthStore = z.infer<typeof AuthStoreSchema>;
306
+ /**
307
+ * 口令哈希记录形态
308
+ */
309
+ type PasswordRecord = z.infer<typeof PasswordRecordSchema>;
310
+ /**
311
+ * token 签发结果 DTO 形态
312
+ */
313
+ type TokenCreateInfo = z.infer<typeof TokenCreateInfoSchema>;
314
+ /**
315
+ * token 信息 DTO 形态
316
+ */
317
+ type TokenInfo = z.infer<typeof TokenInfoSchema>;
318
+ /**
319
+ * token 记录形态
320
+ */
321
+ type TokenRecord = z.infer<typeof TokenRecordSchema>;
322
+ //#endregion
323
+ //#region src/auth.store.d.ts
324
+ /**
325
+ * auth store 工厂参数
326
+ */
327
+ type AuthStoreOptions = {
328
+ /**
329
+ * 集中数据根(auth.json 所在)
330
+ */
331
+ dataRoot: string;
332
+ };
333
+ /**
334
+ * auth store 句柄
335
+ */
336
+ type AuthStoreHandle = {
337
+ /**
338
+ * 建户(单本地用户语义:已有任一用户即拒绝)
339
+ *
340
+ * @param username - 用户名
341
+ * @param password - 口令明文(仅此刻参与运算,绝不落盘)
342
+ * @throws {@link UserAlreadyExistsError} 已存在本地用户时
343
+ */
344
+ createUser(username: string, password: string): void;
345
+ /**
346
+ * 校验口令
347
+ *
348
+ * @param username - 用户名
349
+ * @param password - 口令明文
350
+ * @throws {@link InvalidCredentialsError} 用户不存在或口令不符时
351
+ */
352
+ verifyPassword(username: string, password: string): void;
353
+ /**
354
+ * 读取本地用户名(无用户返回 null——首启未 adduser 状态)
355
+ *
356
+ * @returns 用户名或 null
357
+ */
358
+ getUserName(): string | null;
359
+ /**
360
+ * 签发 token(绑定既有用户)
361
+ *
362
+ * @param username - 绑定用户名(须已建户)
363
+ * @param note - 用途备注(可空)
364
+ * @returns 签发结果(明文仅此一次)
365
+ * @throws {@link InvalidCredentialsError} 用户不存在时
366
+ */
367
+ issueToken(username: string, note?: string): TokenCreateInfo;
368
+ /**
369
+ * token 列表(不含明文)
370
+ *
371
+ * @returns token 信息数组
372
+ */
373
+ listTokens(): TokenInfo[];
374
+ /**
375
+ * 按 id 吊销 token
376
+ *
377
+ * @param id - token 短标识
378
+ * @returns 命中并吊销返回 true
379
+ */
380
+ revokeToken(id: string): boolean;
381
+ /**
382
+ * 校验 Bearer token(已吊销/未知均拒)
383
+ *
384
+ * @param token - token 明文
385
+ * @returns 绑定用户名
386
+ * @throws {@link TokenInvalidError} 无效或已吊销时
387
+ */
388
+ verifyToken(token: string): string;
389
+ };
390
+ /**
391
+ * 创建 auth store(惰性读、变更即原子写回)
392
+ *
393
+ * @param options - 工厂参数
394
+ * @returns auth store 句柄
395
+ */
396
+ declare function createAuthStore(options: AuthStoreOptions): AuthStoreHandle;
397
+ //#endregion
398
+ //#region src/errors.d.ts
399
+ /**
400
+ * 包不存在(→ 404)
401
+ */
402
+ declare class PackageNotFoundError extends DomainError {
403
+ /**
404
+ * 创建包不存在错误
405
+ *
406
+ * @param name - 包名
407
+ */
408
+ constructor(name: string);
409
+ }
410
+ /**
411
+ * 包版本不存在(→ 404)
412
+ */
413
+ declare class PackageVersionNotFoundError extends DomainError {
414
+ /**
415
+ * 创建包版本不存在错误
416
+ *
417
+ * @param name - 包名
418
+ * @param version - 版本号
419
+ */
420
+ constructor(name: string, version: string);
421
+ }
422
+ /**
423
+ * 版本已存在——publish 不可变纪律(→ 409)
424
+ */
425
+ declare class VersionExistsError extends DomainError {
426
+ /**
427
+ * 创建版本已存在错误
428
+ *
429
+ * @param name - 包名
430
+ * @param version - 版本号
431
+ */
432
+ constructor(name: string, version: string);
433
+ }
434
+ /**
435
+ * 修订号不匹配——unpublish 乐观并发守卫(→ 409)
436
+ */
437
+ declare class RevisionMismatchError extends DomainError {
438
+ /**
439
+ * 创建修订号不匹配错误
440
+ *
441
+ * @param name - 包名
442
+ * @param expected - 客户端携带的 _rev
443
+ * @param actual - 存储当前 _rev
444
+ */
445
+ constructor(name: string, expected: string, actual: string);
446
+ }
447
+ /**
448
+ * publish 载荷不合法(→ 400)
449
+ */
450
+ declare class PublishPayloadError extends DomainError {
451
+ /**
452
+ * 创建 publish 载荷错误
453
+ *
454
+ * @param reason - 具体原因(人读中文)
455
+ */
456
+ constructor(reason: string);
457
+ }
458
+ /**
459
+ * npm 协议请求载荷不合法(非 publish 场景,如 adduser/dist-tags,→ 400)
460
+ */
461
+ declare class ProtocolPayloadError extends DomainError {
462
+ /**
463
+ * 创建协议载荷错误
464
+ *
465
+ * @param kind - 载荷场景(如 adduser / dist-tags)
466
+ * @param reason - 具体原因(人读中文)
467
+ */
468
+ constructor(kind: string, reason: string);
469
+ }
470
+ /**
471
+ * 附件 shasum 与声明不符(→ 400)
472
+ */
473
+ declare class ShasumMismatchError extends DomainError {
474
+ /**
475
+ * 创建 shasum 不符错误
476
+ *
477
+ * @param name - 包名
478
+ * @param version - 版本号
479
+ * @param declared - 载荷声明值
480
+ * @param actual - 附件实测值
481
+ */
482
+ constructor(name: string, version: string, declared: string, actual: string);
483
+ }
484
+ /**
485
+ * 包名不在允许 scope 内(→ 403,防误当通用 registry)
486
+ */
487
+ declare class ScopeNotAllowedError extends DomainError {
488
+ /**
489
+ * 创建 scope 不允许错误
490
+ *
491
+ * @param name - 包名
492
+ */
493
+ constructor(name: string);
494
+ }
495
+ /**
496
+ * token 无效或已吊销(→ 401)
497
+ */
498
+ declare class TokenInvalidError extends DomainError {
499
+ /**
500
+ * 创建 token 无效错误
501
+ */
502
+ constructor();
503
+ }
504
+ /**
505
+ * 本地用户已存在(单本地用户语义,→ 409)
506
+ */
507
+ declare class UserAlreadyExistsError extends DomainError {
508
+ /**
509
+ * 创建用户已存在错误
510
+ *
511
+ * @param name - 已存在的用户名
512
+ */
513
+ constructor(name: string);
514
+ }
515
+ /**
516
+ * 用户名或口令错误(→ 401)
517
+ */
518
+ declare class InvalidCredentialsError extends DomainError {
519
+ /**
520
+ * 创建凭据错误
521
+ */
522
+ constructor();
523
+ }
524
+ //#endregion
525
+ //#region src/package.operations.d.ts
526
+ /**
527
+ * publish 结果
528
+ */
529
+ type PublishResult = {
530
+ /**
531
+ * 发布后修订号
532
+ */
533
+ rev: string;
534
+ /**
535
+ * 本次发布版本号
536
+ */
537
+ version: string;
538
+ };
539
+ /**
540
+ * unpublish 结果
541
+ */
542
+ type UnpublishResult = {
543
+ /**
544
+ * 操作后修订号(整包移除时为末次修订号)
545
+ */
546
+ rev: string;
547
+ };
548
+ //#endregion
549
+ //#region src/registry.engine.d.ts
550
+ /**
551
+ * 引擎工厂参数
552
+ */
553
+ type LocalNpmRegistryOptions = {
554
+ /**
555
+ * 集中数据根
556
+ */
557
+ dataRoot: string;
558
+ /**
559
+ * 允许发布的包名正则(null = 不设防;缺省 null)
560
+ */
561
+ allowPublish?: RegExp | null;
562
+ };
563
+ /**
564
+ * 引擎句柄
565
+ */
566
+ type LocalNpmRegistry = {
567
+ /**
568
+ * 初始化目录布局(幂等:store/ + run/)
569
+ */
570
+ ensureLayout(): void;
571
+ /**
572
+ * 读取落盘 packument(不含 tarball 注入;未托管返回 null)
573
+ *
574
+ * @param name - 包名
575
+ * @returns packument 或 null
576
+ */
577
+ readPackument(name: string): Packument | null;
578
+ /**
579
+ * 读取单版本 manifest(versionOrTag 可为版本号或 dist-tag 名)
580
+ *
581
+ * @param name - 包名
582
+ * @param versionOrTag - 版本号或 tag
583
+ * @returns manifest 或 null
584
+ */
585
+ readManifest(name: string, versionOrTag: string): VersionManifest | null;
586
+ /**
587
+ * 读取 tarball 字节
588
+ *
589
+ * @param name - 包名
590
+ * @param version - 版本号
591
+ * @returns 字节内容或 null
592
+ */
593
+ readTarball(name: string, version: string): Uint8Array | null;
594
+ /**
595
+ * 读取 dist-tag 映射
596
+ *
597
+ * @param name - 包名
598
+ * @returns 映射或 null
599
+ */
600
+ readDistTags(name: string): DistTagMap | null;
601
+ /**
602
+ * 发布新版本(载荷校验 / shasum 实测 / 附件落盘 / packument 合并)
603
+ *
604
+ * @param payload - npm publish 请求体
605
+ * @param actor - 发布者身份(maintainers 缺省来源)
606
+ * @returns 发布结果
607
+ * @throws {@link PublishPayloadError} 载荷不合法(400)
608
+ * @throws {@link ScopeNotAllowedError} 包名不在允许 scope(403)
609
+ * @throws {@link ShasumMismatchError} 附件哈希不符(400)
610
+ * @throws {@link VersionExistsError} 版本已存在(409)
611
+ */
612
+ publish(payload: unknown, actor: string): PublishResult;
613
+ /**
614
+ * 下线单版本(rev 乐观并发校验;最后一个版本下线即整包移除)
615
+ *
616
+ * @param name - 包名
617
+ * @param version - 版本号
618
+ * @param rev - 客户端携带的 _rev
619
+ * @returns 操作结果
620
+ * @throws {@link PackageNotFoundError} 包不存在(404)
621
+ * @throws {@link RevisionMismatchError} 修订号不匹配(409)
622
+ * @throws {@link PackageVersionNotFoundError} 版本不存在(404)
623
+ */
624
+ unpublishVersion(name: string, version: string, rev: string): UnpublishResult;
625
+ /**
626
+ * 整包下线(rev 校验后移除目录)
627
+ *
628
+ * @param name - 包名
629
+ * @param rev - 客户端携带的 _rev
630
+ * @returns 操作结果(末次修订号)
631
+ * @throws {@link PackageNotFoundError} 包不存在(404)
632
+ * @throws {@link RevisionMismatchError} 修订号不匹配(409)
633
+ */
634
+ unpublishPackage(name: string, rev: string): UnpublishResult;
635
+ /**
636
+ * 整体替换 dist-tags(PUT 语义;指向的版本必须存在)
637
+ *
638
+ * @param name - 包名
639
+ * @param tags - 新映射
640
+ * @throws {@link PackageNotFoundError} 包不存在(404)
641
+ * @throws {@link PackageVersionNotFoundError} 指向版本不存在(404)
642
+ */
643
+ replaceDistTags(name: string, tags: DistTagMap): void;
644
+ /**
645
+ * 增改单个 dist-tag(POST 语义)
646
+ *
647
+ * @param name - 包名
648
+ * @param tag - tag 名
649
+ * @param version - 指向版本
650
+ * @throws {@link PackageNotFoundError} 包不存在(404)
651
+ * @throws {@link PackageVersionNotFoundError} 指向版本不存在(404)
652
+ */
653
+ addDistTag(name: string, tag: string, version: string): void;
654
+ /**
655
+ * 删除单个 dist-tag(DELETE 语义)
656
+ *
657
+ * @param name - 包名
658
+ * @param tag - tag 名
659
+ * @returns 命中删除返回 true
660
+ */
661
+ removeDistTag(name: string, tag: string): boolean;
662
+ /**
663
+ * 本地包摘要列表(按名排序)
664
+ *
665
+ * @returns 摘要数组
666
+ */
667
+ listPackages(): PackageSummary[];
668
+ /**
669
+ * 本地包计数
670
+ *
671
+ * @returns 包数
672
+ */
673
+ countPackages(): number;
674
+ };
675
+ /**
676
+ * 创建本地 registry 引擎
677
+ *
678
+ * @param options - 工厂参数
679
+ * @returns 引擎句柄
680
+ */
681
+ declare function createLocalNpmRegistry(options: LocalNpmRegistryOptions): LocalNpmRegistry;
682
+ //#endregion
683
+ //#region src/store.utils.d.ts
684
+ /**
685
+ * 存储布局与基础工具:目录布局 / 转义命名 / 原子写 / 哈希 / 语义化版本比较 / 修订号。
686
+ *
687
+ * 布局(<DATA_ROOT>):
688
+ * store/<escaped>/{index.json, tarballs/<basename>-<version>.tgz}
689
+ * auth.json
690
+ * run/(daemon 运行态)
691
+ *
692
+ * 原子写沿用工作区惯例:tmp(pid 后缀)+ rename。
693
+ */
694
+ /**
695
+ * 构造包存储目录路径
696
+ *
697
+ * @param dataRoot - 集中数据根
698
+ * @param name - 包名(原始形态,含 scope)
699
+ * @returns store/<escaped> 绝对路径
700
+ */
701
+ declare function packageDirPath(dataRoot: string, name: string): string;
702
+ /**
703
+ * 构造 packument 落盘路径
704
+ *
705
+ * @param dataRoot - 集中数据根
706
+ * @param name - 包名
707
+ * @returns index.json 绝对路径
708
+ */
709
+ declare function packumentPath(dataRoot: string, name: string): string;
710
+ /**
711
+ * 构造 tarball 落盘路径
712
+ *
713
+ * @param dataRoot - 集中数据根
714
+ * @param name - 包名
715
+ * @param version - 版本号
716
+ * @returns tarball 绝对路径
717
+ */
718
+ declare function tarballPath(dataRoot: string, name: string, version: string): string;
719
+ /**
720
+ * 包名 → 目录名转义(scoped 的 `/` → `%2f`,对齐 npm 生态惯例)
721
+ *
722
+ * @param name - 包名
723
+ * @returns 转义后的目录名
724
+ */
725
+ declare function escapePackageName(name: string): string;
726
+ /**
727
+ * 目录名 → 包名还原
728
+ *
729
+ * @param escaped - 转义后的目录名
730
+ * @returns 原始包名
731
+ */
732
+ declare function unescapePackageName(escaped: string): string;
733
+ /**
734
+ * tarball 文件名(scoped 取 basename;`<basename>-<version>.tgz`)
735
+ *
736
+ * @param name - 包名
737
+ * @param version - 版本号
738
+ * @returns tarball 文件名
739
+ */
740
+ declare function tarballFileName(name: string, version: string): string;
741
+ /**
742
+ * 原子写 JSON(tmp + rename;tmp 带 pid 后缀防并发碰撞)
743
+ *
744
+ * @param filePath - 目标路径
745
+ * @param value - 可 JSON 序列化的值
746
+ */
747
+ declare function atomicWriteJson(filePath: string, value: unknown): void;
748
+ /**
749
+ * 原子写二进制(tmp + rename;tmp 带 pid 后缀防并发碰撞)
750
+ *
751
+ * @param filePath - 目标路径
752
+ * @param bytes - 字节内容
753
+ */
754
+ declare function atomicWriteBytes(filePath: string, bytes: Uint8Array): void;
755
+ /**
756
+ * sha1 十六进制(tarball shasum 校验/生成)
757
+ *
758
+ * @param bytes - 输入字节
759
+ * @returns 40 位十六进制摘要
760
+ */
761
+ declare function sha1Hex(bytes: Uint8Array): string;
762
+ /**
763
+ * sha256 十六进制(口令/token 哈希)
764
+ *
765
+ * @param input - 输入文本
766
+ * @returns 64 位十六进制摘要
767
+ */
768
+ declare function sha256Hex(input: string): string;
769
+ /**
770
+ * 当前时刻 ISO 文本
771
+ *
772
+ * @returns ISO 8601 文本
773
+ */
774
+ declare function nowIso(): string;
775
+ /**
776
+ * 语义化版本比较(忽略 build 后缀;prerelease 按点分段数值/词典序,无 prerelease > 有)
777
+ *
778
+ * @param a - 版本甲
779
+ * @param b - 版本乙
780
+ * @returns 负数甲旧 / 0 相等 / 正数甲新
781
+ */
782
+ declare function compareSemver(a: string, b: string): number;
783
+ /**
784
+ * 下一修订号(`N-hash`:计数 +1,hash 取随机 8 位十六进制;缺省计数按 0 起)
785
+ *
786
+ * @param current - 当前修订号(可选——透传可选语义下可能缺省)
787
+ * @returns 新修订号
788
+ */
789
+ declare function nextRevision(current: string | undefined): string;
790
+ //#endregion
791
+ export { AUTH_STORE_VERSION, type AuthStore, type AuthStoreHandle, type AuthStoreOptions, AuthStoreSchema, COUCHDB_USER_ID_PREFIX, type CouchUserPayload, CouchUserPayloadSchema, DIST_TAG_PATTERN, type DistMeta, DistMetaSchema, type DistTagMap, DistTagMapSchema, InvalidCredentialsError, type LocalNpmRegistry, type LocalNpmRegistryOptions, type NpmErrorResponse, NpmErrorResponseSchema, PACKAGE_NAME_PATTERN, type PackageDetail, PackageDetailSchema, type PackageIdentifier, PackageIdentifierSchema, PackageNotFoundError, type PackageSummary, PackageSummarySchema, PackageVersionNotFoundError, type Packument, PackumentSchema, type PasswordRecord, PasswordRecordSchema, ProtocolPayloadError, type PublishAttachment, PublishAttachmentSchema, type PublishPayload, PublishPayloadError, PublishPayloadSchema, type PublishResponse, PublishResponseSchema, type PublishResult, RevisionMismatchError, SEMVER_PATTERN, ScopeNotAllowedError, type Semver, SemverSchema, ShasumMismatchError, TOKEN_PREFIX, type TokenCreateInfo, TokenCreateInfoSchema, type TokenInfo, TokenInfoSchema, TokenInvalidError, type TokenRecord, TokenRecordSchema, type UnpublishResult, UserAlreadyExistsError, VersionExistsError, type VersionManifest, VersionManifestSchema, type WhoamiResponse, WhoamiResponseSchema, atomicWriteBytes, atomicWriteJson, compareSemver, createAuthStore, createLocalNpmRegistry, escapePackageName, nextRevision, nowIso, packageDirPath, packumentPath, sha1Hex, sha256Hex, tarballFileName, tarballPath, unescapePackageName };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import"./rolldown-runtime-BqT_7tdF.js";import*as e from"zod";import{existsSync as t,mkdirSync as n,readFileSync as r,readdirSync as i,renameSync as a,rmSync as o,unlinkSync as s,writeFileSync as c}from"node:fs";import{join as l}from"node:path";import{DomainError as u}from"@longzai-intelligence-error/core";import{createHash as d,randomBytes as f}from"node:crypto";const p=/^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/,m=/^\d+\.\d+\.\d+(-[0-9A-Za-z-.+]+)?(\+[0-9A-Za-z-.]+)?$/,h=/^[a-z][a-z0-9-._]*$/i,g=`org.couchdb.user:`,_=e.string().regex(p),v=e.string().regex(m),y=e.object({shasum:e.string().regex(/^[0-9a-f]{40}$/).optional(),integrity:e.string().optional(),tarball:e.string().url().optional(),fileCount:e.number().int().nonnegative().optional(),unpackedSize:e.number().int().nonnegative().optional()}),b=e.looseObject({name:_,version:v,dist:y}),x=e.record(e.string().regex(h),v),S=e.looseObject({_id:_,_rev:e.string().regex(/^\d+-[0-9a-f]+$/).optional(),name:_,description:e.string().optional(),"dist-tags":x,versions:e.record(v,b),time:e.record(e.string(),e.string()).optional(),maintainers:e.array(e.looseObject({name:e.string(),email:e.string().optional()})).optional(),readme:e.string().optional()}),C=e.object({content_type:e.string(),data:e.string(),length:e.number().int().nonnegative()}),w=e.looseObject({_id:_.optional(),name:_,description:e.string().optional(),"dist-tags":x,versions:e.record(v,b).refine(e=>Object.keys(e).length>=1,{error:`publish 载荷 versions 至少含一个新版本`}),access:e.enum([`public`,`restricted`]).nullish(),readme:e.string().optional(),_attachments:e.record(e.string(),C).refine(e=>Object.keys(e).length>=1,{error:`publish 载荷 _attachments 至少含一个 tarball`}),maintainers:e.array(e.looseObject({name:e.string(),email:e.string().optional()})).optional()}).refine(e=>e._id===void 0||e._id===e.name,{error:`publish 载荷 _id 与 name 不一致`,path:[`_id`]}),ee=e.object({ok:e.literal(!0),rev:e.string(),id:e.string().optional()}),te=e.object({username:e.string().min(1)}),ne=e.looseObject({_id:e.string().optional(),name:e.string().min(1).regex(/^[a-z][a-z0-9-]*$/i,{error:`用户名仅允许字母数字与中划线`}),password:e.string().min(1),email:e.email().optional(),type:e.literal(`user`).optional(),roles:e.array(e.string()).optional(),date:e.string().optional()}),re=e.object({error:e.string()}),ie=e.object({name:_,versionCount:e.number().int().positive(),latest:v.optional(),modified:e.string().datetime().optional()}),ae=e.object({name:_,versionCount:e.number().int().positive(),latest:v.optional(),modified:e.string().datetime().optional(),distTags:x,versions:e.array(v)}),T=`lzi_local_`,oe=1,E=e.object({salt:e.string().regex(/^[0-9a-f]{32}$/),hash:e.string().regex(/^[0-9a-f]{64}$/)}),D=e.object({id:e.string().regex(/^[0-9a-f]{8}$/),username:e.string().min(1),tokenHash:e.string().regex(/^[0-9a-f]{64}$/),note:e.string().optional(),createdAt:e.string().datetime(),revokedAt:e.string().datetime().optional()}),O=e.object({version:e.literal(1),users:e.record(e.string(),e.object({password:E})),tokens:e.array(D)}),se=e.object({id:e.string().regex(/^[0-9a-f]{8}$/),token:e.string(),note:e.string().optional(),createdAt:e.string().datetime()}),ce=e.object({id:e.string().regex(/^[0-9a-f]{8}$/),note:e.string().optional(),createdAt:e.string().datetime(),revoked:e.boolean()});var k=class extends u{constructor(e){super(`包不存在: ${e}`,`NPM_REGISTRY_PACKAGE_NOT_FOUND`,{name:e}),this.name=`PackageNotFoundError`}},A=class extends u{constructor(e,t){super(`包版本不存在: ${e}@${t}`,`NPM_REGISTRY_PACKAGE_VERSION_NOT_FOUND`,{name:e,version:t}),this.name=`PackageVersionNotFoundError`}},j=class extends u{constructor(e,t){super(`版本已存在,npm 版本不可变: ${e}@${t}`,`NPM_REGISTRY_VERSION_EXISTS`,{name:e,version:t}),this.name=`VersionExistsError`}},M=class extends u{constructor(e,t,n){super(`修订号不匹配(携带 ${t},当前 ${n}),请重新获取 packument`,`NPM_REGISTRY_REVISION_MISMATCH`,{name:e,expected:t,actual:n}),this.name=`RevisionMismatchError`}},N=class extends u{constructor(e){super(`publish 载荷不合法: ${e}`,`NPM_REGISTRY_PUBLISH_PAYLOAD_INVALID`,{reason:e}),this.name=`PublishPayloadError`}},le=class extends u{constructor(e,t){super(`${e} 载荷不合法: ${t}`,`NPM_REGISTRY_PROTOCOL_PAYLOAD_INVALID`,{kind:e,reason:t}),this.name=`ProtocolPayloadError`}},P=class extends u{constructor(e,t,n,r){super(`tarball shasum 不符(声明 ${n},实测 ${r}): ${e}@${t}`,`NPM_REGISTRY_SHASUM_MISMATCH`,{name:e,version:t,declared:n,actual:r}),this.name=`ShasumMismatchError`}},F=class extends u{constructor(e){super(`包名不在允许发布的 scope 内: ${e}`,`NPM_REGISTRY_SCOPE_NOT_ALLOWED`,{name:e}),this.name=`ScopeNotAllowedError`}},I=class extends u{constructor(){super(`token 无效或已吊销`,`NPM_REGISTRY_TOKEN_INVALID`,{}),this.name=`TokenInvalidError`}},L=class extends u{constructor(e){super(`本地用户已存在: ${e}`,`NPM_REGISTRY_USER_ALREADY_EXISTS`,{name:e}),this.name=`UserAlreadyExistsError`}},R=class extends u{constructor(){super(`用户名或口令错误`,`NPM_REGISTRY_INVALID_CREDENTIALS`,{}),this.name=`InvalidCredentialsError`}};function z(e,t){return l(e,`store`,H(t))}function B(e,t){return l(z(e,t),`index.json`)}function V(e,t,n){return l(z(e,t),`tarballs`,U(t,n))}function H(e){return e.replace(/\//g,`%2f`)}function ue(e){return e.replace(/%2f/g,`/`)}function U(e,t){return`${e.split(`/`).at(-1)??e}-${t}.tgz`}function W(e,t){let n=`${e}.${process.pid}.tmp`;c(n,`${JSON.stringify(t,null,2)}\n`,`utf8`),a(n,e)}function G(e,t){let n=`${e}.${process.pid}.tmp`;c(n,t),a(n,e)}function K(e){t(e)||n(e,{recursive:!0})}function q(e){return d(`sha1`).update(e).digest(`hex`)}function J(e){return d(`sha256`).update(e).digest(`hex`)}function Y(e){return f(e).toString(`hex`)}function X(){return(/* @__PURE__ */ new Date()).toISOString()}function Z(e){let[t=``]=e.split(`+`),[n=``,r]=t.split(`-`),[i=0,a=0,o=0]=n.split(`.`).map(e=>Number.parseInt(e,10));return{core:[i,a,o],pre:r===void 0?null:r.split(`.`)}}function Q(e,t){let n=Z(e),r=Z(t);for(let e=0;e<3;e++){let t=n.core[e]??0,i=r.core[e]??0;if(t!==i)return t-i}return n.pre===null&&r.pre===null?0:n.pre===null?1:r.pre===null?-1:de(n.pre,r.pre)}function de(e,t){let n=Math.min(e.length,t.length);for(let r=0;r<n;r++){let n=e[r]??``,i=t[r]??``,a=/^\d+$/.test(n),o=/^\d+$/.test(i);if(a&&o){let e=Number.parseInt(n,10)-Number.parseInt(i,10);if(e!==0)return e;continue}if(a)return-1;if(o)return 1;if(n!==i)return n<i?-1:1}return e.length-t.length}function $(e){return`${Number.parseInt(e?.split(`-`)[0]??`0`,10)+1}-${Y(4)}`}function fe(e){let n=l(e.dataRoot,`auth.json`),i=()=>{if(!t(n))return{version:1,users:{},tokens:[]};let e=O.safeParse(JSON.parse(r(n,`utf8`)));if(!e.success)throw Error(`[core] auth.json 不合法:${e.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`; `)}`);return e.data},a=e=>{W(n,e)};return{createUser:(e,t)=>{let n=i(),r=Object.keys(n.users)[0];if(r!==void 0)throw new L(r);let o=Y(16);n.users[e]={password:{salt:o,hash:J(o+t)}},a(n)},verifyPassword:(e,t)=>{let n=i().users[e];if(n===void 0||J(n.password.salt+t)!==n.password.hash)throw new R},getUserName:()=>{let e=i(),t=Object.keys(e.users)[0];return t===void 0?null:t},issueToken:(e,t)=>{let n=i();if(n.users[e]===void 0)throw new R;let r=`${T}${Y(24)}`,o={id:Y(4),username:e,tokenHash:J(r),createdAt:X(),...t!==void 0&&t!==``?{note:t}:{}};return n.tokens.push(o),a(n),{id:o.id,token:r,createdAt:o.createdAt,...o.note===void 0?{}:{note:o.note}}},listTokens:()=>i().tokens.map(e=>({id:e.id,createdAt:e.createdAt,revoked:e.revokedAt!==void 0,...e.note===void 0?{}:{note:e.note}})),revokeToken:e=>{let t=i(),n=t.tokens.find(t=>t.id===e);return n===void 0||n.revokedAt!==void 0?!1:(n.revokedAt=X(),a(t),!0)},verifyToken:e=>{let t=i(),n=J(e),r=t.tokens.find(e=>e.tokenHash===n&&e.revokedAt===void 0);if(r===void 0)throw new I;return r.username}}}function pe(e,t,n){let r=w.safeParse(t);if(!r.success)throw new N(r.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`; `));let i=r.data;if(e.allowPublish!==null&&!e.allowPublish.test(i.name))throw new F(i.name);let a=Object.keys(i.versions);if(a.length!==1)throw new N(`仅支持单版本发布,收到 ${a.length} 个`);let o=Object.keys(i._attachments);if(o.length!==1)throw new N(`仅支持单附件发布,收到 ${o.length} 个`);let s=a[0];if(s===void 0)throw new N(`versions 键缺失`);let c=i.versions[s];if(c===void 0)throw new N(`versions[${s}] manifest 缺失`);let u=o[0];if(u===void 0)throw new N(`_attachments 键缺失`);let d=i._attachments[u];if(d===void 0)throw new N(`_attachments[${u}] 附件缺失`);let f;try{f=new Uint8Array(Buffer.from(d.data,`base64`))}catch{throw new N(`附件 base64 解码失败`)}if(f.length!==d.length)throw new N(`附件长度不符(声明 ${d.length},实测 ${f.length})`);let p=q(f);if(c.dist.shasum!==void 0&&c.dist.shasum!==p)throw new P(i.name,s,c.dist.shasum,p);let m=e.readPackument(i.name)??{_id:i.name,_rev:`0-0`,name:i.name,"dist-tags":{},versions:{},time:{}};if(m.versions[s]!==void 0)throw new j(i.name,s);K(l(z(e.dataRoot,i.name),`tarballs`)),G(V(e.dataRoot,i.name,s),f);let h={...c,dist:{...c.dist,shasum:p}};delete h.dist.tarball,m.time??={};let g=X();m.versions[s]=h;for(let[e,t]of Object.entries(i[`dist-tags`]))m[`dist-tags`][e]=t;return m.time[s]=g,m.time.created??=g,m.time.modified=g,m.maintainers??=i.maintainers??[{name:n}],m.description=i.description??m.description,i.readme!==void 0&&(m.readme=i.readme),m._rev=$(m._rev),e.writePackument(m),{rev:m._rev??`0-0`,version:s}}function me(e,n,r,i){if(i.versions[r]===void 0)throw new A(n,r);let a=V(e.dataRoot,n,r);t(a)&&s(a),delete i.versions[r],i.time!==void 0&&delete i.time[r];for(let[e,t]of Object.entries(i[`dist-tags`]))t===r&&delete i[`dist-tags`][e];let c=Object.keys(i.versions);if(c.length===0){let t=$(i._rev);return o(z(e.dataRoot,n),{recursive:!0,force:!0}),{rev:t}}if(i[`dist-tags`].latest===void 0){let e=c[0];if(e!==void 0){let t=c.reduce((e,t)=>Q(t,e)>0?t:e,e);i[`dist-tags`].latest=t}}return i.time??={},i.time.modified=X(),i._rev=$(i._rev),e.writePackument(i),{rev:i._rev??`0-0`}}function he(e,t,n){let r=$(n._rev);return o(z(e.dataRoot,t),{recursive:!0,force:!0}),{rev:r}}function ge(e){let n=l(e.dataRoot,`store`),a=e.allowPublish??null,o=n=>{let i=B(e.dataRoot,n);if(!t(i))return null;let a=S.safeParse(JSON.parse(r(i,`utf8`)));return a.success?a.data:null},s=(e,t)=>{let n=o(e);if(n===null)throw new k(e);if(n._rev!==t)throw new M(e,t,n._rev??`0-0`);return n},c=t=>{K(z(e.dataRoot,t.name)),W(B(e.dataRoot,t.name),t)},u={dataRoot:e.dataRoot,allowPublish:a,readPackument:o,writePackument:c},d=()=>{K(n),K(l(e.dataRoot,`run`))},f=e=>o(e),p=(e,t)=>{let n=o(e);if(n===null)return null;let r=n[`dist-tags`][t]??t;return n.versions[r]??null},m=(n,i)=>{let a=V(e.dataRoot,n,i);return t(a)?new Uint8Array(r(a)):null},h=e=>{let t=o(e);return t===null?null:t[`dist-tags`]},g=(e,t)=>pe(u,e,t),_=(e,t,n)=>me(u,e,t,s(e,n)),v=(e,t)=>he(u,e,s(e,t)),y=(e,t)=>{let n=o(e);if(n===null)throw new k(e);for(let r of Object.values(t))if(n.versions[r]===void 0)throw new A(e,r);n[`dist-tags`]={...t},n.time??={},n.time.modified=X(),n._rev=$(n._rev),c(n)},b=(e,t,n)=>{let r=o(e);if(r===null)throw new k(e);if(r.versions[n]===void 0)throw new A(e,n);r[`dist-tags`][t]=n,r.time??={},r.time.modified=X(),r._rev=$(r._rev),c(r)},x=(e,t)=>{let n=o(e);return n===null||n[`dist-tags`][t]===void 0?!1:(delete n[`dist-tags`][t],n.time??={},n.time.modified=X(),n._rev=$(n._rev),c(n),!0)},C=()=>{if(!t(n))return[];let e=[];for(let t of i(n,{withFileTypes:!0})){if(!t.isDirectory())continue;let n=t.name.replace(/%2f/g,`/`),r=o(n);r!==null&&e.push({name:n,versionCount:Object.keys(r.versions).length,...r[`dist-tags`].latest===void 0?{}:{latest:r[`dist-tags`].latest},...r.time?.modified===void 0?{}:{modified:r.time.modified}})}return e.sort((e,t)=>e.name<t.name?-1:+(e.name>t.name))};return{ensureLayout:d,readPackument:f,readManifest:p,readTarball:m,readDistTags:h,publish:g,unpublishVersion:_,unpublishPackage:v,replaceDistTags:y,addDistTag:b,removeDistTag:x,listPackages:C,countPackages:()=>C().length}}export{oe as AUTH_STORE_VERSION,O as AuthStoreSchema,g as COUCHDB_USER_ID_PREFIX,ne as CouchUserPayloadSchema,h as DIST_TAG_PATTERN,y as DistMetaSchema,x as DistTagMapSchema,R as InvalidCredentialsError,re as NpmErrorResponseSchema,p as PACKAGE_NAME_PATTERN,ae as PackageDetailSchema,_ as PackageIdentifierSchema,k as PackageNotFoundError,ie as PackageSummarySchema,A as PackageVersionNotFoundError,S as PackumentSchema,E as PasswordRecordSchema,le as ProtocolPayloadError,C as PublishAttachmentSchema,N as PublishPayloadError,w as PublishPayloadSchema,ee as PublishResponseSchema,M as RevisionMismatchError,m as SEMVER_PATTERN,F as ScopeNotAllowedError,v as SemverSchema,P as ShasumMismatchError,T as TOKEN_PREFIX,se as TokenCreateInfoSchema,ce as TokenInfoSchema,I as TokenInvalidError,D as TokenRecordSchema,L as UserAlreadyExistsError,j as VersionExistsError,b as VersionManifestSchema,te as WhoamiResponseSchema,G as atomicWriteBytes,W as atomicWriteJson,Q as compareSemver,fe as createAuthStore,ge as createLocalNpmRegistry,H as escapePackageName,$ as nextRevision,X as nowIso,z as packageDirPath,B as packumentPath,q as sha1Hex,J as sha256Hex,U as tarballFileName,V as tarballPath,ue as unescapePackageName};
@@ -0,0 +1 @@
1
+ import"node:module";export{};
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@longzai-intelligence-npm-registry/core",
3
+ "version": "0.0.1",
4
+ "description": "Longzai Intelligence 本地 npm registry 存储引擎与数据契约:npm 协议载荷 / publish 校验落盘 / dist-tags / unpublish / 单用户鉴权(零 HTTP、零上游感知)",
5
+ "license": "UNLICENSED",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "type": "module",
10
+ "main": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js"
16
+ }
17
+ },
18
+ "scripts": {
19
+ "build": "lzi-builder",
20
+ "build:prod": "NODE_ENV=production bun run build",
21
+ "prepublishOnly": "bun run build:prod",
22
+ "typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
23
+ "typecheck:app": "lzi-tsgo typecheck tsconfig/app.json",
24
+ "typecheck:node": "lzi-tsgo typecheck tsconfig/node.json",
25
+ "typecheck:test": "lzi-tsgo typecheck tsconfig/test.json",
26
+ "lint": "oxlint && oxfmt --check",
27
+ "lint:fix": "oxlint --fix && oxfmt",
28
+ "test": "bun test",
29
+ "test:watch": "bun test --watch",
30
+ "test:coverage": "bun test --coverage",
31
+ "clean": "lzi-dev-cli clean"
32
+ },
33
+ "dependencies": {
34
+ "@longzai-intelligence-error/core": "^0.1.0",
35
+ "zod": "^4.4.3"
36
+ }
37
+ }