@molecule/api-resource 1.0.4 → 1.0.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.
package/README.md CHANGED
@@ -3,15 +3,11 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
3
  Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
4
  Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
5
  To change this document, edit the module-level JSDoc in src/index.ts.
6
- Generated: 2026-10-16T20:59:23.498Z
6
+ Generated: 2026-10-23T21:27:14.472Z
7
7
  -->
8
8
 
9
9
  # @molecule/api-resource
10
10
 
11
- > **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
12
- > It is written to be read by coding agents as much as by people, and is generated from this
13
- > package's source — edit `src/index.ts` JSDoc, not this file.
14
-
15
11
  Base resource patterns for molecule.dev.
16
12
 
17
13
  Provides CRUD operation factories and request handler utilities for
@@ -34,6 +30,10 @@ res.status(statusCode).send(body)
34
30
  Monkey-patching `res.json` (or `res.send`/`res.end`) to re-shape a handler's answer intercepts
35
31
  nothing the handler produces, so the request it was meant to answer is left unanswered and hangs.
36
32
 
33
+ > **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
34
+ > It is written to be read by coding agents as much as by people, and is generated from this
35
+ > package's source — edit `src/index.ts` JSDoc, not this file.
36
+
37
37
  ## Quick Start
38
38
 
39
39
  ```typescript
@@ -120,10 +120,21 @@ Framework-agnostic HTTP request interface. Structurally compatible with Express'
120
120
  `Request` — Express objects satisfy this interface without adapters, but the type
121
121
  doesn't depend on Express, allowing use with Fastify, Hono, or Lambda.
122
122
 
123
+ `params` is `Record<string, any>` on purpose. Express 5 declares
124
+ `ParamsDictionary` as `{ [key: string]: string | string[] }` — a wildcard or a
125
+ repeated parameter yields an array — so `Record<string, string>` is NOT a
126
+ supertype of it, and every Express handler passing its own `Request` to a
127
+ function declared on this interface (`authorization.set(req, …)`) failed with
128
+ TS2345 and was told to cast. This is the same shape `body` and `query` already
129
+ use. A reader that needs one segment as a string checks it
130
+ (`typeof req.params.id === 'string'`) rather than trusting the annotation;
131
+ the packages that own the routes do exactly that where it matters (see
132
+ `@molecule/api-bonds-default-express`'s `getParamId`).
133
+
123
134
  ```typescript
124
135
  interface MoleculeRequest {
125
136
  body: any
126
- params: Record<string, string>
137
+ params: Record<string, any>
127
138
  query: Record<string, any>
128
139
  headers: Record<string, string | string[] | undefined>
129
140
  cookies?: Record<string, string>
@@ -588,7 +599,7 @@ returned by resource CRUD operations.
588
599
  ```typescript
589
600
  function responseSchema(
590
601
  propsSchema: T,
591
- ): z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>
602
+ ): z.ZodTypeAny<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>
592
603
  ```
593
604
 
594
605
  - `propsSchema` — The Zod schema for the resource's props (e.g. `userPropsSchema`).
@@ -603,7 +614,7 @@ Creates a Zod schema that validates a resource descriptor object
603
614
  ```typescript
604
615
  function resourceSchema(
605
616
  _propsSchema: T,
606
- ): z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>
617
+ ): z.ZodTypeAny<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>
607
618
  ```
608
619
 
609
620
  - `_propsSchema` — The Zod schema for the resource's props (used for type inference only).
@@ -617,7 +628,7 @@ human-readable message listing all validation failures if invalid.
617
628
 
618
629
  ```typescript
619
630
  function validate(
620
- schema: z.ZodType<T, unknown, z.core.$ZodTypeInternals<T, unknown>>,
631
+ schema: z.ZodSchema<T, unknown, z.core.$ZodTypeInternals<T, unknown>>,
621
632
  data: unknown,
622
633
  ): T
623
634
  ```
@@ -634,7 +645,7 @@ union: `{ success: true, data }` on success or `{ success: false, error }` on fa
634
645
 
635
646
  ```typescript
636
647
  function safeParse(
637
- schema: z.ZodType<T, unknown, z.core.$ZodTypeInternals<T, unknown>>,
648
+ schema: z.ZodSchema<T, unknown, z.core.$ZodTypeInternals<T, unknown>>,
638
649
  data: unknown,
639
650
  ): { success: true; data: T } | { success: false; error: z.ZodError }
640
651
  ```
@@ -786,6 +797,16 @@ interface Response<T = unknown> {
786
797
 
787
798
  Re-exported as a namespace — reach every member below through it (e.g. `utilities.<name>`).
788
799
 
800
+ ##### `utilities.ZodSchema` _(deprecated)_
801
+
802
+ ```typescript
803
+ type ZodSchema<
804
+ Output = unknown,
805
+ Input = unknown,
806
+ Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>,
807
+ > = ZodType<Output, Input, Internals>
808
+ ```
809
+
789
810
  ##### `utilities.ZodError`
790
811
 
791
812
  An Error-like class used to store Zod validation issues.
@@ -807,151 +828,6 @@ interface ZodError<T = unknown> extends $ZodError<T> {
807
828
  }
808
829
  ```
809
830
 
810
- ##### `utilities.ZodSchema`
811
-
812
- ````typescript
813
- interface ZodType<
814
- out Output = unknown,
815
- out Input = unknown,
816
- out Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<
817
- Output,
818
- Input
819
- >,
820
- > extends core.$ZodType<Output, Input, Internals> {
821
- def: Internals['def']
822
- type: Internals['def']['type']
823
- /** @deprecated Use `.def` instead. */
824
- _def: Internals['def']
825
- /** @deprecated Use `z.output<typeof schema>` instead. */
826
- _output: Internals['output']
827
- /** @deprecated Use `z.input<typeof schema>` instead. */
828
- _input: Internals['input']
829
- '~standard': ZodStandardSchemaWithJSON<this>
830
- /** Converts this schema to a JSON Schema representation. */
831
- toJSONSchema(params?: core.ToJSONSchemaParams): core.ZodStandardJSONSchemaPayload<this>
832
- check(...checks: (core.CheckFn<core.output<this>> | core.$ZodCheck<core.output<this>>)[]): this
833
- with(...checks: (core.CheckFn<core.output<this>> | core.$ZodCheck<core.output<this>>)[]): this
834
- clone(
835
- def?: Internals['def'],
836
- params?: {
837
- parent: boolean
838
- },
839
- ): this
840
- register<R extends core.$ZodRegistry>(
841
- registry: R,
842
- ...meta: this extends R['_schema']
843
- ? undefined extends R['_meta']
844
- ? [core.$replace<R['_meta'], this>?]
845
- : [core.$replace<R['_meta'], this>]
846
- : ['Incompatible schema']
847
- ): this
848
- brand<T extends PropertyKey = PropertyKey, Dir extends 'in' | 'out' | 'inout' = 'out'>(
849
- value?: T,
850
- ): PropertyKey extends T ? this : core.$ZodBranded<this, T, Dir>
851
- parse(data: unknown, params?: core.ParseContext<core.$ZodIssue>): core.output<this>
852
- safeParse(
853
- data: unknown,
854
- params?: core.ParseContext<core.$ZodIssue>,
855
- ): parse.ZodSafeParseResult<core.output<this>>
856
- parseAsync(data: unknown, params?: core.ParseContext<core.$ZodIssue>): Promise<core.output<this>>
857
- safeParseAsync(
858
- data: unknown,
859
- params?: core.ParseContext<core.$ZodIssue>,
860
- ): Promise<parse.ZodSafeParseResult<core.output<this>>>
861
- spa: (
862
- data: unknown,
863
- params?: core.ParseContext<core.$ZodIssue>,
864
- ) => Promise<parse.ZodSafeParseResult<core.output<this>>>
865
- encode(data: core.output<this>, params?: core.ParseContext<core.$ZodIssue>): core.input<this>
866
- decode(data: core.input<this>, params?: core.ParseContext<core.$ZodIssue>): core.output<this>
867
- encodeAsync(
868
- data: core.output<this>,
869
- params?: core.ParseContext<core.$ZodIssue>,
870
- ): Promise<core.input<this>>
871
- decodeAsync(
872
- data: core.input<this>,
873
- params?: core.ParseContext<core.$ZodIssue>,
874
- ): Promise<core.output<this>>
875
- safeEncode(
876
- data: core.output<this>,
877
- params?: core.ParseContext<core.$ZodIssue>,
878
- ): parse.ZodSafeParseResult<core.input<this>>
879
- safeDecode(
880
- data: core.input<this>,
881
- params?: core.ParseContext<core.$ZodIssue>,
882
- ): parse.ZodSafeParseResult<core.output<this>>
883
- safeEncodeAsync(
884
- data: core.output<this>,
885
- params?: core.ParseContext<core.$ZodIssue>,
886
- ): Promise<parse.ZodSafeParseResult<core.input<this>>>
887
- safeDecodeAsync(
888
- data: core.input<this>,
889
- params?: core.ParseContext<core.$ZodIssue>,
890
- ): Promise<parse.ZodSafeParseResult<core.output<this>>>
891
- refine<Ch extends (arg: core.output<this>) => unknown | Promise<unknown>>(
892
- check: Ch,
893
- params?: string | core.$ZodCustomParams,
894
- ): Ch extends (arg: any) => arg is infer R ? this & ZodType<R, core.input<this>> : this
895
- superRefine(
896
- refinement: (
897
- arg: core.output<this>,
898
- ctx: core.$RefinementCtx<core.output<this>>,
899
- ) => void | Promise<void>,
900
- params?: core.$ZodSuperRefineParams,
901
- ): this
902
- overwrite(fn: (x: core.output<this>) => core.output<this>): this
903
- optional(): ZodOptional<this>
904
- exactOptional(): ZodExactOptional<this>
905
- nonoptional(params?: string | core.$ZodNonOptionalParams): ZodNonOptional<this>
906
- nullable(): ZodNullable<this>
907
- nullish(): ZodOptional<ZodNullable<this>>
908
- default(def: util.NoUndefined<core.output<this>>): ZodDefault<this>
909
- default(def: () => util.NoUndefined<core.output<this>>): ZodDefault<this>
910
- prefault(def: () => core.input<this>): ZodPrefault<this>
911
- prefault(def: core.input<this>): ZodPrefault<this>
912
- array(): ZodArray<this>
913
- or<T extends core.SomeType>(option: T): ZodUnion<[this, T]>
914
- and<T extends core.SomeType>(incoming: T): ZodIntersection<this, T>
915
- transform<NewOut>(
916
- transform: (
917
- arg: core.output<this>,
918
- ctx: core.$RefinementCtx<core.output<this>>,
919
- ) => NewOut | Promise<NewOut>,
920
- ): ZodPipe<this, ZodTransform<Awaited<NewOut>, core.output<this>>>
921
- catch(def: core.output<this>): ZodCatch<this>
922
- catch(def: (ctx: core.$ZodCatchCtx) => core.output<this>): ZodCatch<this>
923
- pipe<T extends core.$ZodType<any, core.output<this>>>(
924
- target: T | core.$ZodType<any, core.output<this>>,
925
- ): ZodPipe<this, T>
926
- readonly(): ZodReadonly<this>
927
- /** Returns a new instance that has been registered in `z.globalRegistry` with the specified description */
928
- describe(description: string): this
929
- description?: string
930
- /** Returns the metadata associated with this instance in `z.globalRegistry` */
931
- meta(): core.$replace<core.GlobalMeta, this> | undefined
932
- /** Returns a new instance that has been registered in `z.globalRegistry` with the specified metadata */
933
- meta(data: core.$replace<core.GlobalMeta, this>): this
934
- /** @deprecated Try safe-parsing `undefined` (this is what `isOptional` does internally):
935
- *
936
- * ```ts
937
- * const schema = z.string().optional();
938
- * const isOptional = schema.safeParse(undefined).success; // true
939
- * ```
940
- */
941
- isOptional(): boolean
942
- /**
943
- * @deprecated Try safe-parsing `null` (this is what `isNullable` does internally):
944
- *
945
- * ```ts
946
- * const schema = z.string().nullable();
947
- * const isNullable = schema.safeParse(null).success; // true
948
- * ```
949
- */
950
- isNullable(): boolean
951
- apply<T>(fn: (schema: this) => T): T
952
- }
953
- ````
954
-
955
831
  ##### `utilities.getValidProps`
956
832
 
957
833
  Validates resource props against a Zod schema, returning typed valid props or throwing
@@ -11,10 +11,21 @@
11
11
  * Framework-agnostic HTTP request interface. Structurally compatible with Express's
12
12
  * `Request` — Express objects satisfy this interface without adapters, but the type
13
13
  * doesn't depend on Express, allowing use with Fastify, Hono, or Lambda.
14
+ *
15
+ * `params` is `Record<string, any>` on purpose. Express 5 declares
16
+ * `ParamsDictionary` as `{ [key: string]: string | string[] }` — a wildcard or a
17
+ * repeated parameter yields an array — so `Record<string, string>` is NOT a
18
+ * supertype of it, and every Express handler passing its own `Request` to a
19
+ * function declared on this interface (`authorization.set(req, …)`) failed with
20
+ * TS2345 and was told to cast. This is the same shape `body` and `query` already
21
+ * use. A reader that needs one segment as a string checks it
22
+ * (`typeof req.params.id === 'string'`) rather than trusting the annotation;
23
+ * the packages that own the routes do exactly that where it matters (see
24
+ * `@molecule/api-bonds-default-express`'s `getParamId`).
14
25
  */
15
26
  export interface MoleculeRequest {
16
27
  body: any;
17
- params: Record<string, string>;
28
+ params: Record<string, any>;
18
29
  query: Record<string, any>;
19
30
  headers: Record<string, string | string[] | undefined>;
20
31
  cookies?: Record<string, string>;
@@ -1 +1 @@
1
- {"version":3,"file":"http-types.d.ts","sourceRoot":"","sources":["../src/http-types.ts"],"names":[],"mappings":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AAG,IAAI,CAAA;IAC1C,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5C,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAA;IAC5E,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAA;IACtC,YAAY,CAAC,IAAI,IAAI,CAAA;IACrB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAC5B;AAED;;;;;GAKG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,GAAG,CAAC,EAAE,OAAO,KAAK,IAAI,CAAA;AAE1D;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG,CACnC,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,gBAAgB,EACrB,IAAI,EAAE,oBAAoB,KACvB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/api-resource",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Resource CRUD operations and utilities for molecule.dev.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -35,17 +35,17 @@
35
35
  ],
36
36
  "license": "Apache-2.0",
37
37
  "dependencies": {
38
- "uuid": "14.0.1",
39
- "zod": "4.4.3"
38
+ "uuid": "14.0.3",
39
+ "zod": "4.6.7"
40
40
  },
41
41
  "devDependencies": {
42
- "@molecule/api-bond": "1.0.2",
43
- "@molecule/api-database": "1.1.3",
42
+ "@molecule/api-bond": "1.0.3",
43
+ "@molecule/api-database": "1.1.5",
44
44
  "@molecule/api-locales-resource": "1.0.2",
45
- "@molecule/api-utilities-validation": "1.0.2",
46
- "@types/node": "26.1.2",
45
+ "@molecule/api-utilities-validation": "1.0.3",
46
+ "@types/node": "26.6.5",
47
47
  "typescript": "6.0.3",
48
- "vitest": "4.1.11"
48
+ "vitest": "4.1.12"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "@molecule/api-bond": "^1.0.1",