@effected/package-json 0.1.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/index.d.ts ADDED
@@ -0,0 +1,747 @@
1
+ import { CatalogResolver, DependencyKind, DependencyProtocol, DependencyProtocol as DependencyProtocol$1, DependencySpecifier, DependencySpecifierBrand, InvalidDependencySpecifierError, WorkspaceResolver, isValidDependencySpecifier } from "@effected/npm";
2
+ import { InvalidVersionError, Range, SemVer } from "@effected/semver";
3
+ import { Brand, Context, Effect, FileSystem, HashMap, Layer, Option, Path, Schema } from "effect";
4
+ //#region src/Dependency.d.ts
5
+ declare const Dependency_base: Schema.Class<Dependency, Schema.Struct<{
6
+ /** The package name. */
7
+ readonly name: Schema.String;
8
+ /** The raw version specifier. */
9
+ readonly specifier: Schema.String;
10
+ /** Which dependency map this entry came from. */
11
+ readonly kind: Schema.Literals<readonly ["prod", "dev", "peer", "optional"]>;
12
+ /** For `peer` dependencies, whether the peer is optional (from `peerDependenciesMeta`). */
13
+ readonly isOptional: Schema.optionalKey<Schema.Boolean>;
14
+ }>, {}>;
15
+ /**
16
+ * A resolved dependency entry pairing a package name with its version
17
+ * specifier and the `kind` of map it came from (`@effected/npm`'s
18
+ * `DependencyKind`). The protocol predicates delegate to `DependencySpecifier`.
19
+ *
20
+ * @public
21
+ */
22
+ declare class Dependency extends Dependency_base {
23
+ /** The classified protocol, or `None` for an empty specifier. */
24
+ get protocol(): Option.Option<DependencyProtocol$1>;
25
+ /** Parse the specifier as a semver `Range`, `None` when it is not a range. */
26
+ get range(): Option.Option<Range>;
27
+ /** Whether the specifier points to a local path. */
28
+ get isLocal(): boolean;
29
+ /** Whether the specifier uses the `link:` protocol. */
30
+ get isLink(): boolean;
31
+ /** Whether the specifier uses the `portal:` protocol. */
32
+ get isPortal(): boolean;
33
+ /** Whether the specifier uses the `catalog:` protocol. */
34
+ get isCatalog(): boolean;
35
+ /** Whether the specifier uses the `workspace:` protocol. */
36
+ get isWorkspace(): boolean;
37
+ /** Whether the specifier is an unresolved `catalog:` or `workspace:` protocol. */
38
+ get isUnresolved(): boolean;
39
+ /** Whether the specifier resolves to a git source. */
40
+ get isGit(): boolean;
41
+ /** Whether the specifier is a parseable semver range. */
42
+ get isRange(): boolean;
43
+ /** Whether the specifier is a dist-tag. */
44
+ get isTag(): boolean;
45
+ }
46
+ /**
47
+ * A {@link Dependency} whose specifier is an unresolved `catalog:` or
48
+ * `workspace:` protocol.
49
+ *
50
+ * @public
51
+ */
52
+ type UnresolvedDependency = Dependency & {
53
+ readonly isUnresolved: true;
54
+ };
55
+ /**
56
+ * Type guard narrowing any dependency-like value to
57
+ * {@link UnresolvedDependency}, preserving the concrete type.
58
+ *
59
+ * @public
60
+ */
61
+ declare const isUnresolvedDependency: <T extends {
62
+ readonly isUnresolved: boolean;
63
+ }>(dependency: T) => dependency is T & {
64
+ readonly isUnresolved: true;
65
+ };
66
+ //#endregion
67
+ //#region src/DevEngines.d.ts
68
+ declare const DevEngine_base: Schema.Class<DevEngine, Schema.Struct<{
69
+ /** The engine name (e.g. `node`, `pnpm`). */
70
+ readonly name: Schema.String;
71
+ /** The optional version constraint. */
72
+ readonly version: Schema.optionalKey<Schema.String>;
73
+ /** The optional behavior when the constraint is unmet. */
74
+ readonly onFail: Schema.optionalKey<Schema.Literals<readonly ["warn", "error", "ignore"]>>;
75
+ }>, {}>;
76
+ /**
77
+ * A single `devEngines` constraint with a name and optional `version` / `onFail`.
78
+ *
79
+ * @public
80
+ */
81
+ declare class DevEngine extends DevEngine_base {}
82
+ /**
83
+ * A `devEngines` constraint slot: a single {@link DevEngine} or an array of them.
84
+ *
85
+ * @public
86
+ */
87
+ declare const DevEngineOrArray: Schema.Union<[typeof DevEngine, Schema.$Array<typeof DevEngine>]>;
88
+ /**
89
+ * The `devEngines` field schema, modeling runtime and package-manager
90
+ * constraints as optional {@link DevEngine} slots.
91
+ *
92
+ * @public
93
+ */
94
+ declare const DevEnginesSchema: Schema.Struct<{
95
+ readonly packageManager: Schema.optionalKey<typeof DevEngineOrArray>;
96
+ readonly runtime: Schema.optionalKey<typeof DevEngineOrArray>;
97
+ readonly os: Schema.optionalKey<typeof DevEngineOrArray>;
98
+ readonly cpu: Schema.optionalKey<typeof DevEngineOrArray>;
99
+ readonly libc: Schema.optionalKey<typeof DevEngineOrArray>;
100
+ }>;
101
+ /**
102
+ * The decoded `devEngines` field type.
103
+ *
104
+ * @public
105
+ */
106
+ type DevEngines = typeof DevEnginesSchema.Type;
107
+ //#endregion
108
+ //#region src/License.d.ts
109
+ declare const InvalidSpdxLicenseError_base: Schema.Class<InvalidSpdxLicenseError, Schema.TaggedStruct<"InvalidSpdxLicenseError", {
110
+ /** The raw input string that failed validation. */
111
+ readonly input: Schema.String;
112
+ }>, import("effect/Cause").YieldableError>;
113
+ /**
114
+ * Indicates that a string is not a valid SPDX license identifier or expression.
115
+ *
116
+ * Raised by {@link Package.setLicense} and the decode direction of
117
+ * `SpdxLicense`. The offending string is preserved on `input`.
118
+ *
119
+ * @public
120
+ */
121
+ declare class InvalidSpdxLicenseError extends InvalidSpdxLicenseError_base {
122
+ get message(): string;
123
+ }
124
+ /**
125
+ * Whether a string is a valid SPDX license identifier or expression, or one of
126
+ * the npm special cases `UNLICENSED` / `SEE LICENSE IN <file>`.
127
+ *
128
+ * @public
129
+ */
130
+ declare const isValidSpdx: (value: string) => boolean;
131
+ /**
132
+ * A valid SPDX license identifier, expression, `UNLICENSED`, or
133
+ * `SEE LICENSE IN <file>`.
134
+ *
135
+ * @public
136
+ */
137
+ declare const SpdxLicense: Schema.brand<Schema.String, "SpdxLicense">;
138
+ /**
139
+ * A branded SPDX license string.
140
+ *
141
+ * @public
142
+ */
143
+ type SpdxLicense = string & Brand.Brand<"SpdxLicense">;
144
+ //#endregion
145
+ //#region src/PackageManager.d.ts
146
+ declare const PackageManager_base: Schema.Class<PackageManager, Schema.Struct<{
147
+ /** The package-manager name (e.g. `pnpm`). */
148
+ readonly name: Schema.String;
149
+ /** The version (e.g. `10.33.0`). */
150
+ readonly version: Schema.String;
151
+ /** The optional integrity hash (e.g. `sha512.abc`), an `@effected/npm` `IntegrityHash` restricted to the corepack `<algo>.<hex>` form. */
152
+ readonly integrity: Schema.Option<Schema.brand<Schema.String, "IntegrityHash">>;
153
+ }>, {}>;
154
+ /**
155
+ * A structured `packageManager` value with `name`, `version` and an optional
156
+ * `integrity` hash.
157
+ *
158
+ * @public
159
+ */
160
+ declare class PackageManager extends PackageManager_base {
161
+ /**
162
+ * Schema transformation between the `"name@version+integrity"` string and a
163
+ * {@link PackageManager}.
164
+ */
165
+ static readonly FromString: Schema.Codec<PackageManager, string>;
166
+ /** Whether an integrity hash is present. */
167
+ get hasIntegrity(): boolean;
168
+ }
169
+ //#endregion
170
+ //#region src/PackageName.d.ts
171
+ declare const InvalidPackageNameError_base: Schema.Class<InvalidPackageNameError, Schema.TaggedStruct<"InvalidPackageNameError", {
172
+ /** The raw input string that failed validation. */
173
+ readonly input: Schema.String;
174
+ }>, import("effect/Cause").YieldableError>;
175
+ /**
176
+ * Indicates that a string could not be used as a valid npm package name.
177
+ *
178
+ * Raised by {@link Package.setName} and the decode direction of
179
+ * `PackageName`. The offending string is preserved on `input`.
180
+ *
181
+ * @public
182
+ */
183
+ declare class InvalidPackageNameError extends InvalidPackageNameError_base {
184
+ get message(): string;
185
+ }
186
+ /**
187
+ * A valid npm scoped package name (`@scope/name`).
188
+ *
189
+ * @public
190
+ */
191
+ declare const ScopedPackageName: Schema.brand<Schema.String, "ScopedPackageName">;
192
+ /**
193
+ * A valid npm scoped package name.
194
+ *
195
+ * @public
196
+ */
197
+ type ScopedPackageName = string & Brand.Brand<"ScopedPackageName">;
198
+ /**
199
+ * A valid npm unscoped package name (no `@scope/` prefix).
200
+ *
201
+ * @public
202
+ */
203
+ declare const UnscopedPackageName: Schema.brand<Schema.String, "UnscopedPackageName">;
204
+ /**
205
+ * A valid npm unscoped package name.
206
+ *
207
+ * @public
208
+ */
209
+ type UnscopedPackageName = string & Brand.Brand<"UnscopedPackageName">;
210
+ /**
211
+ * A valid npm package name, scoped or unscoped.
212
+ *
213
+ * @public
214
+ */
215
+ type PackageName = ScopedPackageName | UnscopedPackageName;
216
+ /**
217
+ * The union of `ScopedPackageName` and `UnscopedPackageName`,
218
+ * carrying the classification statics (`PackageName.isValid` and friends)
219
+ * that absorb the v3 floating `PackageNameUtil` object. Use it as the schema
220
+ * for a package-name field and reach for the statics to inspect a raw string.
221
+ *
222
+ * @public
223
+ */
224
+ declare const PackageName: Schema.Union<readonly [Schema.brand<Schema.String, "ScopedPackageName">, Schema.brand<Schema.String, "UnscopedPackageName">]> & {
225
+ isValid: (name: string) => boolean;
226
+ scope: (name: string) => Option.Option<string>;
227
+ unscoped: (name: string) => string;
228
+ isScoped: (name: string) => boolean;
229
+ };
230
+ //#endregion
231
+ //#region src/Person.d.ts
232
+ declare const Person_base: Schema.Class<Person, Schema.Struct<{
233
+ /** The person's name. */
234
+ readonly name: Schema.String;
235
+ /** The optional email address. */
236
+ readonly email: Schema.optionalKey<Schema.String>;
237
+ /** The optional homepage URL. */
238
+ readonly url: Schema.optionalKey<Schema.String>;
239
+ }>, {}>;
240
+ /**
241
+ * A structured person object with `name` and optional `email` / `url`.
242
+ *
243
+ * @public
244
+ */
245
+ declare class Person extends Person_base {
246
+ /**
247
+ * Schema transformation between the `"Name <email> (url)"` shorthand string
248
+ * and a {@link Person}.
249
+ */
250
+ static readonly FromString: Schema.Codec<Person, string>;
251
+ /**
252
+ * The `author` / `contributors` value: either the shorthand string or the
253
+ * structured object, always decoded to a {@link Person}.
254
+ */
255
+ static readonly FromValue: Schema.Union<[typeof Person, Schema.Codec<Person, string>]>;
256
+ }
257
+ //#endregion
258
+ //#region src/Package.d.ts
259
+ /**
260
+ * A string→string map field decoding a plain JSON object to a `HashMap`,
261
+ * defaulting to an empty map when the key is absent. Backs the four dependency
262
+ * maps and `scripts`. Not meant to be referenced directly.
263
+ *
264
+ * @public
265
+ */
266
+ declare const DependencyMapField: Schema.decodeTo<Schema.HashMap<Schema.String, Schema.String>, Schema.withDecodingDefaultKey<Schema.$Record<Schema.String, Schema.String>, never>, never, never>;
267
+ /**
268
+ * A string→string map field decoding a plain JSON object to a `HashMap`,
269
+ * with no default (an absent key stays absent). Backs `engines`. Not meant to
270
+ * be referenced directly.
271
+ *
272
+ * @public
273
+ */
274
+ declare const StringMapField: Schema.decodeTo<Schema.HashMap<Schema.String, Schema.String>, Schema.$Record<Schema.String, Schema.String>, never, never>;
275
+ /**
276
+ * The `bin` field: a single string path or a name→path map. Not meant to be
277
+ * referenced directly.
278
+ *
279
+ * @public
280
+ */
281
+ declare const BinField: Schema.Union<readonly [Schema.String, Schema.decodeTo<Schema.HashMap<Schema.String, Schema.String>, Schema.$Record<Schema.String, Schema.String>, never, never>]>;
282
+ /**
283
+ * The `exports` field: a single string entry point or an open object of
284
+ * conditional exports. Not meant to be referenced directly.
285
+ *
286
+ * @public
287
+ */
288
+ declare const ExportsField: Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Unknown>]>;
289
+ /**
290
+ * The `publishConfig` field: an open record preserving known npm keys
291
+ * (`access`, `directory`, ...) plus extensions like `targets`. Not meant to be
292
+ * referenced directly.
293
+ *
294
+ * @public
295
+ */
296
+ declare const PublishConfigField: Schema.$Record<Schema.String, Schema.Unknown>;
297
+ /**
298
+ * The `peerDependenciesMeta` field: a map of package name to `{ optional? }`.
299
+ * Not meant to be referenced directly.
300
+ *
301
+ * @public
302
+ */
303
+ declare const PeerDependenciesMetaField: Schema.$Record<Schema.String, Schema.Struct<{
304
+ readonly optional: Schema.optionalKey<Schema.Boolean>;
305
+ }>>;
306
+ /**
307
+ * The `repository` field: a shorthand string or an object (with `type` / `url` /
308
+ * `directory` and any extensions preserved). Not meant to be referenced
309
+ * directly.
310
+ *
311
+ * @public
312
+ */
313
+ declare const RepositoryField: Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Unknown>]>;
314
+ declare const PackageDecodeError_base: Schema.Class<PackageDecodeError, Schema.TaggedStruct<"PackageDecodeError", {
315
+ /** The underlying `SchemaError`, preserved structurally rather than stringified. */
316
+ readonly cause: Schema.Defect;
317
+ }>, import("effect/Cause").YieldableError>;
318
+ /**
319
+ * Indicates that a JSON value could not be decoded into a valid {@link Package}.
320
+ *
321
+ * Raised by {@link Package.decode}. The underlying `SchemaError` is preserved on
322
+ * the structured `cause` field (never stringified), so callers keep the issue
323
+ * tree for diagnostics.
324
+ *
325
+ * @public
326
+ */
327
+ declare class PackageDecodeError extends PackageDecodeError_base {
328
+ get message(): string;
329
+ }
330
+ /**
331
+ * Options for {@link Package.toJsonString} and `PackageJsonFile.write`.
332
+ *
333
+ * @public
334
+ */
335
+ interface PackageFormatOptions {
336
+ /** Indentation width in spaces (default `2`). */
337
+ readonly indent?: number;
338
+ /** Order top-level keys canonically and alphabetize dependency maps (default `true`). */
339
+ readonly sort?: boolean;
340
+ /** Strip empty dependency-map keys (default `true`). */
341
+ readonly stripEmpty?: boolean;
342
+ /** Append a trailing newline (default `true`). */
343
+ readonly newline?: boolean;
344
+ }
345
+ /**
346
+ * A patch over {@link Package}'s modeled fields — every field optional,
347
+ * derived from the schema so it never drifts from the model.
348
+ *
349
+ * @public
350
+ */
351
+ type PackagePatch = Partial<{ readonly [K in keyof (typeof Package)["fields"]]: (typeof Package)["fields"][K]["Type"]; }>;
352
+ declare const Package_base: Schema.Class<Package, Schema.Struct<{
353
+ readonly name: Schema.Union<readonly [Schema.brand<Schema.String, "ScopedPackageName">, Schema.brand<Schema.String, "UnscopedPackageName">]> & {
354
+ isValid: (name: string) => boolean;
355
+ scope: (name: string) => Option.Option<string>;
356
+ unscoped: (name: string) => string;
357
+ isScoped: (name: string) => boolean;
358
+ };
359
+ readonly version: Schema.Codec<SemVer, string, never, never>;
360
+ readonly description: Schema.optionalKey<Schema.String>;
361
+ readonly private: Schema.optionalKey<Schema.Boolean>;
362
+ readonly type: Schema.optionalKey<Schema.Literals<readonly ["module", "commonjs"]>>;
363
+ readonly main: Schema.optionalKey<Schema.String>;
364
+ readonly license: Schema.optionalKey<Schema.brand<Schema.String, "SpdxLicense">>;
365
+ readonly author: Schema.optionalKey<Schema.Union<[typeof Person, Schema.Codec<Person, string, never, never>]>>;
366
+ readonly contributors: Schema.optionalKey<Schema.$Array<Schema.Union<[typeof Person, Schema.Codec<Person, string, never, never>]>>>;
367
+ readonly repository: Schema.optionalKey<Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Unknown>]>>;
368
+ readonly dependencies: Schema.decodeTo<Schema.HashMap<Schema.String, Schema.String>, Schema.withDecodingDefaultKey<Schema.$Record<Schema.String, Schema.String>, never>, never, never>;
369
+ readonly devDependencies: Schema.decodeTo<Schema.HashMap<Schema.String, Schema.String>, Schema.withDecodingDefaultKey<Schema.$Record<Schema.String, Schema.String>, never>, never, never>;
370
+ readonly peerDependencies: Schema.decodeTo<Schema.HashMap<Schema.String, Schema.String>, Schema.withDecodingDefaultKey<Schema.$Record<Schema.String, Schema.String>, never>, never, never>;
371
+ readonly optionalDependencies: Schema.decodeTo<Schema.HashMap<Schema.String, Schema.String>, Schema.withDecodingDefaultKey<Schema.$Record<Schema.String, Schema.String>, never>, never, never>;
372
+ readonly peerDependenciesMeta: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Struct<{
373
+ readonly optional: Schema.optionalKey<Schema.Boolean>;
374
+ }>>>;
375
+ readonly scripts: Schema.decodeTo<Schema.HashMap<Schema.String, Schema.String>, Schema.withDecodingDefaultKey<Schema.$Record<Schema.String, Schema.String>, never>, never, never>;
376
+ readonly bin: Schema.optionalKey<Schema.Union<readonly [Schema.String, Schema.decodeTo<Schema.HashMap<Schema.String, Schema.String>, Schema.$Record<Schema.String, Schema.String>, never, never>]>>;
377
+ readonly engines: Schema.optionalKey<Schema.decodeTo<Schema.HashMap<Schema.String, Schema.String>, Schema.$Record<Schema.String, Schema.String>, never, never>>;
378
+ readonly exports: Schema.optionalKey<Schema.Union<readonly [Schema.String, Schema.$Record<Schema.String, Schema.Unknown>]>>;
379
+ readonly publishConfig: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
380
+ readonly packageManager: Schema.optionalKey<Schema.Codec<PackageManager, string, never, never>>;
381
+ readonly devEngines: Schema.optionalKey<Schema.Struct<{
382
+ readonly packageManager: Schema.optionalKey<typeof DevEngineOrArray>;
383
+ readonly runtime: Schema.optionalKey<typeof DevEngineOrArray>;
384
+ readonly os: Schema.optionalKey<typeof DevEngineOrArray>;
385
+ readonly cpu: Schema.optionalKey<typeof DevEngineOrArray>;
386
+ readonly libc: Schema.optionalKey<typeof DevEngineOrArray>;
387
+ }>>;
388
+ readonly rest: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
389
+ }>, {}>;
390
+ /**
391
+ * A package.json document as a rich `Schema.Class`: typed known fields, a
392
+ * `rest` catch-all preserving unknown top-level fields across a read/edit/write
393
+ * cycle, computed getters, and immutable mutation statics.
394
+ *
395
+ * @example
396
+ * ```ts
397
+ * import { Package } from "@effected/package-json";
398
+ * import { Effect } from "effect";
399
+ *
400
+ * const program = Effect.gen(function* () {
401
+ * const pkg = yield* Package.decode({ name: "my-pkg", version: "1.0.0" });
402
+ * const next = yield* Package.setVersion(pkg, "1.1.0");
403
+ * console.log(next.toJsonString());
404
+ * });
405
+ * ```
406
+ *
407
+ * @public
408
+ */
409
+ declare class Package extends Package_base {
410
+ pipe<A>(this: A): A;
411
+ pipe<A, B>(this: A, ab: (_: A) => B): B;
412
+ pipe<A, B, C>(this: A, ab: (_: A) => B, bc: (_: B) => C): C;
413
+ pipe<A, B, C, D>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D;
414
+ pipe<A, B, C, D, E>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D, de: (_: D) => E): E;
415
+ /**
416
+ * The default wire codec: an open JSON object ↔ a {@link Package} instance,
417
+ * partitioning unknown keys into `rest` and flattening them back on encode.
418
+ */
419
+ static readonly schema: Schema.Codec<Package, {
420
+ readonly [k: string]: unknown;
421
+ }>;
422
+ /**
423
+ * Build the wire codec for a `.extend()`ed subclass, so its custom fields
424
+ * decode as typed members and are excluded from `rest`.
425
+ *
426
+ * @param Class - the extended `Schema.Class`, carrying its own `fields`
427
+ * @returns a codec between an open JSON object and `Class` instances
428
+ */
429
+ static wireFor<Self extends Package>(Class: Schema.Codec<Self, any, any, any> & {
430
+ readonly fields: Record<string, unknown>;
431
+ }): Schema.Codec<Self, {
432
+ readonly [k: string]: unknown;
433
+ }>;
434
+ /**
435
+ * Decode an unknown JSON value into a {@link Package}, normalizing any
436
+ * `SchemaError` to a typed {@link PackageDecodeError} at the boundary.
437
+ *
438
+ * @param input - the parsed package.json JSON value (e.g. from `JSON.parse`)
439
+ * @returns an Effect resolving to the decoded `Package`
440
+ * @throws (typed) `PackageDecodeError` when `input` does not satisfy the schema
441
+ */
442
+ static readonly decode: (input: unknown) => Effect.Effect<Package, PackageDecodeError, never>;
443
+ /** Whether the package is marked private. */
444
+ get isPrivate(): boolean;
445
+ /** Whether the package name is scoped (`@scope/name`). */
446
+ get isScoped(): boolean;
447
+ /** Whether the package is ESM (`"type": "module"`). */
448
+ get isESM(): boolean;
449
+ /** Whether any dependency map contains `name`. */
450
+ hasDependency(name: string): boolean;
451
+ /** The `dependencies` map as {@link Dependency} instances (`kind: "prod"`). */
452
+ getDependencies(): HashMap.HashMap<string, Dependency>;
453
+ /** The `devDependencies` map as {@link Dependency} instances (`kind: "dev"`). */
454
+ getDevDependencies(): HashMap.HashMap<string, Dependency>;
455
+ /** The `peerDependencies` map as {@link Dependency} instances (`kind: "peer"`), carrying `isOptional` from `peerDependenciesMeta`. */
456
+ getPeerDependencies(): HashMap.HashMap<string, Dependency>;
457
+ /** The `optionalDependencies` map as {@link Dependency} instances (`kind: "optional"`). */
458
+ getOptionalDependencies(): HashMap.HashMap<string, Dependency>;
459
+ /** Return a new {@link Package} with the given fields replaced. */
460
+ copyWith(patch: PackagePatch): Package;
461
+ /** Set the version from a string. Fails with `InvalidVersionError`. Dual API. */
462
+ static readonly setVersion: {
463
+ (version: string): (pkg: Package) => Effect.Effect<Package, InvalidVersionError>;
464
+ (pkg: Package, version: string): Effect.Effect<Package, InvalidVersionError>;
465
+ };
466
+ /** Set the package name. Fails with `InvalidPackageNameError`. Dual API. */
467
+ static readonly setName: {
468
+ (name: string): (pkg: Package) => Effect.Effect<Package, InvalidPackageNameError>;
469
+ (pkg: Package, name: string): Effect.Effect<Package, InvalidPackageNameError>;
470
+ };
471
+ /** Set the license from an SPDX string. Fails with `InvalidSpdxLicenseError`. Dual API. */
472
+ static readonly setLicense: {
473
+ (license: string): (pkg: Package) => Effect.Effect<Package, InvalidSpdxLicenseError>;
474
+ (pkg: Package, license: string): Effect.Effect<Package, InvalidSpdxLicenseError>;
475
+ };
476
+ /** Add or replace a `dependencies` entry. Dual API. */
477
+ static readonly addDependency: {
478
+ (name: string, specifier: string): (pkg: Package) => Package;
479
+ (pkg: Package, name: string, specifier: string): Package;
480
+ };
481
+ /** Remove a `dependencies` entry. Dual API. */
482
+ static readonly removeDependency: {
483
+ (name: string): (pkg: Package) => Package;
484
+ (pkg: Package, name: string): Package;
485
+ };
486
+ /** Add or replace a `devDependencies` entry. Dual API. */
487
+ static readonly addDevDependency: {
488
+ (name: string, specifier: string): (pkg: Package) => Package;
489
+ (pkg: Package, name: string, specifier: string): Package;
490
+ };
491
+ /** Remove a `devDependencies` entry. Dual API. */
492
+ static readonly removeDevDependency: {
493
+ (name: string): (pkg: Package) => Package;
494
+ (pkg: Package, name: string): Package;
495
+ };
496
+ /** Add or replace a `peerDependencies` entry. Dual API. */
497
+ static readonly addPeerDependency: {
498
+ (name: string, specifier: string): (pkg: Package) => Package;
499
+ (pkg: Package, name: string, specifier: string): Package;
500
+ };
501
+ /** Remove a `peerDependencies` entry. Dual API. */
502
+ static readonly removePeerDependency: {
503
+ (name: string): (pkg: Package) => Package;
504
+ (pkg: Package, name: string): Package;
505
+ };
506
+ /** Add or replace an `optionalDependencies` entry. Dual API. */
507
+ static readonly addOptionalDependency: {
508
+ (name: string, specifier: string): (pkg: Package) => Package;
509
+ (pkg: Package, name: string, specifier: string): Package;
510
+ };
511
+ /** Remove an `optionalDependencies` entry. Dual API. */
512
+ static readonly removeOptionalDependency: {
513
+ (name: string): (pkg: Package) => Package;
514
+ (pkg: Package, name: string): Package;
515
+ };
516
+ /** Add or replace a `scripts` entry. Dual API. */
517
+ static readonly setScript: {
518
+ (name: string, command: string): (pkg: Package) => Package;
519
+ (pkg: Package, name: string, command: string): Package;
520
+ };
521
+ /** Remove a `scripts` entry. Dual API. */
522
+ static readonly removeScript: {
523
+ (name: string): (pkg: Package) => Package;
524
+ (pkg: Package, name: string): Package;
525
+ };
526
+ /**
527
+ * Resolve `catalog:` and `workspace:` specifiers across all four dependency
528
+ * maps using the `CatalogResolver` and `WorkspaceResolver` from context.
529
+ * Specifiers the resolvers return `None` for are left unchanged. This is the
530
+ * explicit resolution step — `PackageJsonFile.write` never resolves.
531
+ */
532
+ static readonly resolve: (pkg: Package) => Effect.Effect<Package, import("@effected/npm").DependencyResolutionError, CatalogResolver | WorkspaceResolver>;
533
+ /**
534
+ * Serialize to a formatted package.json string: encode through the wire
535
+ * codec (flattening `rest`), then apply the canonical key order, dependency
536
+ * sorting and empty-map stripping unless the options opt out. Pure.
537
+ */
538
+ toJsonString(options?: PackageFormatOptions): string;
539
+ }
540
+ //#endregion
541
+ //#region src/PackageJsonFile.d.ts
542
+ declare const PackageJsonReadError_base: Schema.Class<PackageJsonReadError, Schema.TaggedStruct<"PackageJsonReadError", {
543
+ /** The path that could not be read. */
544
+ readonly path: Schema.String;
545
+ /** The underlying failure, preserved structurally. */
546
+ readonly cause: Schema.Defect;
547
+ }>, import("effect/Cause").YieldableError>;
548
+ /**
549
+ * Indicates that a package.json file could not be read from the filesystem
550
+ * (a filesystem error other than not-found).
551
+ *
552
+ * @public
553
+ */
554
+ declare class PackageJsonReadError extends PackageJsonReadError_base {
555
+ get message(): string;
556
+ }
557
+ declare const PackageJsonNotFoundError_base: Schema.Class<PackageJsonNotFoundError, Schema.TaggedStruct<"PackageJsonNotFoundError", {
558
+ /** The path where package.json was expected. */
559
+ readonly path: Schema.String;
560
+ }>, import("effect/Cause").YieldableError>;
561
+ /**
562
+ * Indicates that no package.json file exists at the expected path. Carries its
563
+ * own tag for `catchTag` routing.
564
+ *
565
+ * @public
566
+ */
567
+ declare class PackageJsonNotFoundError extends PackageJsonNotFoundError_base {
568
+ get message(): string;
569
+ }
570
+ declare const PackageJsonParseError_base: Schema.Class<PackageJsonParseError, Schema.TaggedStruct<"PackageJsonParseError", {
571
+ /** The path whose contents failed to parse as JSON. */
572
+ readonly path: Schema.String;
573
+ /** The underlying `SyntaxError`, preserved structurally. */
574
+ readonly cause: Schema.Defect;
575
+ }>, import("effect/Cause").YieldableError>;
576
+ /**
577
+ * Indicates that a package.json file's contents are not valid JSON.
578
+ *
579
+ * @public
580
+ */
581
+ declare class PackageJsonParseError extends PackageJsonParseError_base {
582
+ get message(): string;
583
+ }
584
+ declare const PackageJsonWriteError_base: Schema.Class<PackageJsonWriteError, Schema.TaggedStruct<"PackageJsonWriteError", {
585
+ /** The path that could not be written. */
586
+ readonly path: Schema.String;
587
+ /** The underlying filesystem failure, preserved structurally. Narrowed to the write failure only. */
588
+ readonly cause: Schema.Defect;
589
+ }>, import("effect/Cause").YieldableError>;
590
+ /**
591
+ * Indicates that a package.json file could not be written to the filesystem.
592
+ * Narrowed to the filesystem-write failure only — never a resolution or encode
593
+ * error.
594
+ *
595
+ * @public
596
+ */
597
+ declare class PackageJsonWriteError extends PackageJsonWriteError_base {
598
+ get message(): string;
599
+ }
600
+ /**
601
+ * The shape of the {@link PackageJsonFile} service — the value produced by
602
+ * {@link PackageJsonFile.make} and carried by its layer.
603
+ *
604
+ * @public
605
+ */
606
+ interface PackageJsonFileShape {
607
+ /**
608
+ * Read and decode a package.json file. Fails with `PackageJsonNotFoundError`
609
+ * (ENOENT), `PackageJsonReadError` (other fs errors), `PackageJsonParseError`
610
+ * (invalid JSON) or `PackageDecodeError` (schema decode).
611
+ */
612
+ readonly read: (path: string) => Effect.Effect<Package, PackageJsonReadError | PackageJsonNotFoundError | PackageJsonParseError | PackageDecodeError>;
613
+ /** Serialize and write a package.json file. Fails with `PackageJsonWriteError`. */
614
+ readonly write: (path: string, pkg: Package, options?: PackageFormatOptions) => Effect.Effect<void, PackageJsonWriteError>;
615
+ }
616
+ declare const PackageJsonFile_base: Context.ServiceClass<PackageJsonFile, "@effected/package-json/PackageJsonFile", PackageJsonFileShape>;
617
+ /**
618
+ * Reads and writes package.json over core `FileSystem` / `Path`. The layer
619
+ * requires those services; provide `@effect/platform-node`'s `NodeFileSystem` /
620
+ * `NodePath` (or a bun equivalent) at the application boundary.
621
+ *
622
+ * @example
623
+ * ```ts
624
+ * import { PackageJsonFile } from "@effected/package-json";
625
+ * import { NodeFileSystem, NodePath } from "@effect/platform-node";
626
+ * import { Effect } from "effect";
627
+ *
628
+ * const program = Effect.gen(function* () {
629
+ * const files = yield* PackageJsonFile;
630
+ * const pkg = yield* files.read("./package.json");
631
+ * console.log(pkg.name);
632
+ * }).pipe(Effect.provide(PackageJsonFile.layer), Effect.provide(NodeFileSystem.layer), Effect.provide(NodePath.layer));
633
+ * ```
634
+ *
635
+ * @public
636
+ */
637
+ declare class PackageJsonFile extends PackageJsonFile_base {
638
+ /** Build the service implementation from `FileSystem` / `Path` in context; use {@link PackageJsonFile.layer} to provide it. */
639
+ static readonly make: Effect.Effect<PackageJsonFileShape, never, FileSystem.FileSystem | Path.Path>;
640
+ /**
641
+ * The live layer. Requires core `FileSystem` / `Path`, provided by the
642
+ * consumer's platform implementation at the edge.
643
+ */
644
+ static readonly layer: Layer.Layer<PackageJsonFile, never, FileSystem.FileSystem | Path.Path>;
645
+ }
646
+ //#endregion
647
+ //#region src/PackageValidator.d.ts
648
+ /**
649
+ * A single validation-rule failure.
650
+ *
651
+ * @public
652
+ */
653
+ interface RuleFailure {
654
+ /** A human-readable description of the failure. */
655
+ readonly message: string;
656
+ /** The JSON path where the failure occurred; `Option.none()` when not applicable. */
657
+ readonly path: Option.Option<string>;
658
+ }
659
+ /**
660
+ * A single validation rule: a name and a check that fails with a
661
+ * {@link RuleFailure}.
662
+ *
663
+ * @public
664
+ */
665
+ interface ValidationRule {
666
+ /** The rule identifier (e.g. `has-license`). */
667
+ readonly name: string;
668
+ /** The check — succeeds or fails with a {@link RuleFailure}. */
669
+ readonly validate: (pkg: Package) => Effect.Effect<void, RuleFailure>;
670
+ }
671
+ declare const PackageValidationError_base: Schema.Class<PackageValidationError, Schema.TaggedStruct<"PackageValidationError", {
672
+ /** The aggregated rule failures. */
673
+ readonly failures: Schema.$Array<Schema.Struct<{
674
+ readonly rule: Schema.String;
675
+ readonly message: Schema.String;
676
+ readonly path: Schema.Option<Schema.String>;
677
+ }>>;
678
+ }>, import("effect/Cause").YieldableError>;
679
+ /**
680
+ * Indicates that a {@link Package} failed one or more validation rules.
681
+ *
682
+ * Raised by {@link PackageValidator}. Every rule failure is aggregated on
683
+ * `failures`; the `message` getter renders a multi-line report.
684
+ *
685
+ * @public
686
+ */
687
+ declare class PackageValidationError extends PackageValidationError_base {
688
+ get message(): string;
689
+ }
690
+ /**
691
+ * A rule that fails when any dependency uses an unresolved `workspace:` or
692
+ * `catalog:` specifier.
693
+ *
694
+ * @public
695
+ */
696
+ declare const noUnresolvedDepsRule: ValidationRule;
697
+ /**
698
+ * A rule that fails when any dependency uses a local `file:`, `link:` or
699
+ * `portal:` specifier.
700
+ *
701
+ * @public
702
+ */
703
+ declare const noLocalDepsRule: ValidationRule;
704
+ /**
705
+ * The default validation rules: license, description, repository and
706
+ * not-private.
707
+ *
708
+ * @public
709
+ */
710
+ declare const defaultRules: ReadonlyArray<ValidationRule>;
711
+ declare const PackageValidator_base: Context.ServiceClass<PackageValidator, "@effected/package-json/PackageValidator", {
712
+ readonly validate: (pkg: Package) => Effect.Effect<void, PackageValidationError>;
713
+ }>;
714
+ /**
715
+ * Validates a {@link Package} against a set of {@link ValidationRule}s,
716
+ * aggregating every failure into one {@link PackageValidationError}.
717
+ *
718
+ * @example
719
+ * ```ts
720
+ * import { Package, PackageValidator } from "@effected/package-json";
721
+ * import { Effect } from "effect";
722
+ *
723
+ * const program = Effect.gen(function* () {
724
+ * const pkg = yield* Package.decode({ name: "my-pkg", version: "1.0.0" });
725
+ * const validator = yield* PackageValidator;
726
+ * yield* validator.validate(pkg);
727
+ * }).pipe(Effect.provide(PackageValidator.layer));
728
+ * ```
729
+ *
730
+ * @public
731
+ */
732
+ declare class PackageValidator extends PackageValidator_base {
733
+ /** The default layer, backed by {@link defaultRules}. */
734
+ static readonly layer: Layer.Layer<PackageValidator>;
735
+ /**
736
+ * Build a layer from a custom set of rules (a genuinely-parameterized factory).
737
+ *
738
+ * @param config - the rule set to validate against, replacing {@link defaultRules}
739
+ * @returns a layer providing `PackageValidator` backed by `config.rules`
740
+ */
741
+ static layerRules(config: {
742
+ readonly rules: ReadonlyArray<ValidationRule>;
743
+ }): Layer.Layer<PackageValidator>;
744
+ }
745
+ //#endregion
746
+ export { BinField, Dependency, type DependencyKind, DependencyMapField, type DependencyProtocol, DependencySpecifier, type DependencySpecifierBrand, DevEngine, DevEngineOrArray, type DevEngines, DevEnginesSchema, ExportsField, InvalidDependencySpecifierError, InvalidPackageNameError, InvalidSpdxLicenseError, Package, PackageDecodeError, type PackageFormatOptions, PackageJsonFile, type PackageJsonFileShape, PackageJsonNotFoundError, PackageJsonParseError, PackageJsonReadError, PackageJsonWriteError, PackageManager, PackageName, type PackagePatch, PackageValidationError, PackageValidator, PeerDependenciesMetaField, Person, PublishConfigField, RepositoryField, type RuleFailure, ScopedPackageName, SpdxLicense, StringMapField, type UnresolvedDependency, UnscopedPackageName, type ValidationRule, defaultRules, isUnresolvedDependency, isValidDependencySpecifier, isValidSpdx, noLocalDepsRule, noUnresolvedDepsRule };
747
+ //# sourceMappingURL=index.d.ts.map