@molecule/api-resource 1.0.1 → 1.0.3

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 (3) hide show
  1. package/LICENSE +111 -24
  2. package/README.md +494 -50
  3. package/package.json +7 -7
package/LICENSE CHANGED
@@ -1,3 +1,4 @@
1
+
1
2
  Apache License
2
3
  Version 2.0, January 2004
3
4
  http://www.apache.org/licenses/
@@ -34,21 +35,33 @@
34
35
 
35
36
  "Work" shall mean the work of authorship, whether in Source or
36
37
  Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work.
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
38
40
 
39
41
  "Derivative Works" shall mean any work, whether in Source or Object
40
42
  form, that is based on (or derived from) the Work and for which the
41
43
  editorial revisions, annotations, elaborations, or other modifications
42
- represent, as a whole, an original work of authorship.
43
-
44
- "Contribution" shall mean any work of authorship, including the
45
- original version of the Work and any modifications or additions
46
- to that Work, that is intentionally submitted to the Licensor for
47
- inclusion in the Work by the copyright owner or by an individual or
48
- Legal Entity authorized to submit on behalf of the copyright owner.
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
49
62
 
50
63
  "Contributor" shall mean Licensor and any individual or Legal Entity
51
- on behalf of whom a Contribution has been received by the Licensor and
64
+ on behalf of whom a Contribution has been received by Licensor and
52
65
  subsequently incorporated within the Work.
53
66
 
54
67
  2. Grant of Copyright License. Subject to the terms and conditions of
@@ -61,8 +74,18 @@
61
74
  3. Grant of Patent License. Subject to the terms and conditions of
62
75
  this License, each Contributor hereby grants to You a perpetual,
63
76
  worldwide, non-exclusive, no-charge, royalty-free, irrevocable
64
- patent license to make, have made, use, offer to sell, sell, import,
65
- and otherwise transfer the Work.
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
66
89
 
67
90
  4. Redistribution. You may reproduce and distribute copies of the
68
91
  Work or Derivative Works thereof in any medium, with or without
@@ -84,23 +107,87 @@
84
107
  (d) If the Work includes a "NOTICE" text file as part of its
85
108
  distribution, then any Derivative Works that You distribute must
86
109
  include a readable copy of the attribution notices contained
87
- within such NOTICE file.
88
-
89
- 5. Submission of Contributions.
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
90
138
 
91
139
  6. Trademarks. This License does not grant permission to use the trade
92
- names, trademarks, service marks, or product names of the Licensor.
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
93
143
 
94
144
  7. Disclaimer of Warranty. Unless required by applicable law or
95
- agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
96
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
97
-
98
- 8. Limitation of Liability. In no event and under no legal theory shall
99
- any Contributor be liable to You for damages.
100
-
101
- 9. Accepting Warranty or Additional Liability.
102
-
103
- Copyright 2026 Molecule Dev, Inc.
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
104
191
 
105
192
  Licensed under the Apache License, Version 2.0 (the "License");
106
193
  you may not use this file except in compliance with the License.
package/README.md CHANGED
@@ -3,7 +3,7 @@ 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-08-04T01:49:07.015Z
6
+ Generated: 2026-10-16T00:47:45.548Z
7
7
  -->
8
8
 
9
9
  # @molecule/api-resource
@@ -76,19 +76,25 @@ npm install @molecule/api-resource @molecule/api-bond @molecule/api-database @mo
76
76
 
77
77
  ### Interfaces
78
78
 
79
- #### `ErrorFallback`
79
+ #### `Response`
80
80
 
81
- Fallback HTTP response used when a caught error is NOT a molecule-tagged error
82
- (i.e. a genuinely-unexpected failure).
81
+ Structured response object returned by resource handlers. Contains the HTTP
82
+ status code, optional headers, and the response body payload.
83
83
 
84
84
  ```typescript
85
- interface ErrorFallback {
86
- /** HTTP status for the fallback (typically 500). */
87
- status: number
88
- /** Human-readable fallback message (already localized by the caller). */
89
- message: string
90
- /** Machine-readable key the frontend maps to a localized message. */
91
- errorKey: string
85
+ interface Response {
86
+ /**
87
+ * HTTP status code to return.
88
+ */
89
+ statusCode: number
90
+ /**
91
+ * Optional map of HTTP header keys to values.
92
+ */
93
+ headers?: Record<string, string>
94
+ /**
95
+ * The response payload to return.
96
+ */
97
+ body: any
92
98
  }
93
99
  ```
94
100
 
@@ -191,25 +197,19 @@ interface Query {
191
197
  }
192
198
  ```
193
199
 
194
- #### `Response`
200
+ #### `ErrorFallback`
195
201
 
196
- Structured response object returned by resource handlers. Contains the HTTP
197
- status code, optional headers, and the response body payload.
202
+ Fallback HTTP response used when a caught error is NOT a molecule-tagged error
203
+ (i.e. a genuinely-unexpected failure).
198
204
 
199
205
  ```typescript
200
- interface Response {
201
- /**
202
- * HTTP status code to return.
203
- */
204
- statusCode: number
205
- /**
206
- * Optional map of HTTP header keys to values.
207
- */
208
- headers?: Record<string, string>
209
- /**
210
- * The response payload to return.
211
- */
212
- body: any
206
+ interface ErrorFallback {
207
+ /** HTTP status for the fallback (typically 500). */
208
+ status: number
209
+ /** Human-readable fallback message (already localized by the caller). */
210
+ message: string
211
+ /** Machine-readable key the frontend maps to a localized message. */
212
+ errorKey: string
213
213
  }
214
214
  ```
215
215
 
@@ -228,6 +228,9 @@ type Handler = (
228
228
  ) => Promise<Response | null | undefined> | Response | null | undefined
229
229
  ```
230
230
 
231
+ - `req` — The incoming HTTP request.
232
+ - `res` — The HTTP response (available but handlers should return a Response instead of calling `res` directly).
233
+
231
234
  #### `MoleculeNextFunction`
232
235
 
233
236
  Framework-agnostic next function. Call with no arguments to pass to the next
@@ -237,6 +240,8 @@ middleware, or with an error to trigger error-handling middleware.
237
240
  type MoleculeNextFunction = (err?: unknown) => void
238
241
  ```
239
242
 
243
+ - `err` — Optional error to forward to error-handling middleware.
244
+
240
245
  #### `MoleculeRequestHandler`
241
246
 
242
247
  Framework-agnostic middleware function signature matching Express's
@@ -537,38 +542,477 @@ const querySchema: z.ZodObject<
537
542
 
538
543
  #### `schema`
539
544
 
540
- Members:
545
+ Re-exported as a namespace — reach every member below through it (e.g. `schema.<name>`).
546
+
547
+ ##### `schema.basePropsSchema`
548
+
549
+ Base Zod schema with the three fields every resource row must have:
550
+ `id` (UUID), `createdAt` (ISO datetime), and `updatedAt` (ISO datetime).
551
+
552
+ ```typescript
553
+ const basePropsSchema: z.ZodObject<
554
+ { id: z.ZodString; createdAt: z.ZodString; updatedAt: z.ZodString },
555
+ z.core.$strip
556
+ >
557
+ ```
558
+
559
+ ##### `schema.BaseProps`
560
+
561
+ TypeScript type inferred from `basePropsSchema`, containing `id`, `createdAt`, and `updatedAt`.
562
+
563
+ ```typescript
564
+ type BaseProps = z.infer<typeof basePropsSchema>
565
+ ```
566
+
567
+ ##### `schema.responseSchema(propsSchema)`
568
+
569
+ Creates a Zod schema for the standard `{ statusCode, body }` response
570
+ returned by resource CRUD operations.
571
+
572
+ ```typescript
573
+ function responseSchema(
574
+ propsSchema: T,
575
+ ): z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>
576
+ ```
577
+
578
+ - `propsSchema` — The Zod schema for the resource's props (e.g. `userPropsSchema`).
579
+
580
+ **Returns:** A Zod schema that validates `{ statusCode: number, body: { props? } | T[] }`.
581
+
582
+ ##### `schema.resourceSchema(_propsSchema)`
583
+
584
+ Creates a Zod schema that validates a resource descriptor object
585
+ (`{ name, tableName, schema }`).
586
+
587
+ ```typescript
588
+ function resourceSchema(
589
+ _propsSchema: T,
590
+ ): z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>
591
+ ```
541
592
 
542
- - `schema.basePropsSchema` — const: Base Zod schema with the three fields every resource row must have:
543
- - `schema.BaseProps` — type: TypeScript type inferred from `basePropsSchema`, containing `id`, `createdAt`, and `updatedAt`.
544
- - `schema.responseSchema` — function: Creates a Zod schema for the standard `{ statusCode, body }` response
545
- - `schema.resourceSchema` — function: Creates a Zod schema that validates a resource descriptor object
546
- - `schema.validate` — function: Validates data against a Zod schema, throwing an `Error` with a
547
- - `schema.safeParse` — function: Validates data against a Zod schema without throwing. Returns a discriminated
548
- - `schema.partial` — function: Creates a schema where all fields are optional, suitable for validating
549
- - `schema.pick` — function: Creates a schema with only the specified fields, useful for create payloads
593
+ - `_propsSchema` — The Zod schema for the resource's props (used for type inference only).
594
+
595
+ **Returns:** A Zod schema that validates the resource descriptor shape.
596
+
597
+ ##### `schema.validate(schema, data)`
598
+
599
+ Validates data against a Zod schema, throwing an `Error` with a
600
+ human-readable message listing all validation failures if invalid.
601
+
602
+ ```typescript
603
+ function validate(
604
+ schema: z.ZodType<T, unknown, z.core.$ZodTypeInternals<T, unknown>>,
605
+ data: unknown,
606
+ ): T
607
+ ```
608
+
609
+ - `schema` — The Zod schema to validate against.
610
+ - `data` — The data to validate.
611
+
612
+ **Returns:** The parsed and typed data if validation succeeds.
613
+
614
+ ##### `schema.safeParse(schema, data)`
615
+
616
+ Validates data against a Zod schema without throwing. Returns a discriminated
617
+ union: `{ success: true, data }` on success or `{ success: false, error }` on failure.
618
+
619
+ ```typescript
620
+ function safeParse(
621
+ schema: z.ZodType<T, unknown, z.core.$ZodTypeInternals<T, unknown>>,
622
+ data: unknown,
623
+ ): { success: true; data: T } | { success: false; error: z.ZodError }
624
+ ```
625
+
626
+ - `schema` — The Zod schema to validate against.
627
+ - `data` — The data to validate.
628
+
629
+ **Returns:** A discriminated union indicating success with parsed data, or failure with a `ZodError`.
630
+
631
+ ##### `schema.partial(schema)`
632
+
633
+ Creates a schema where all fields are optional, suitable for validating
634
+ partial update payloads where only changed fields are sent.
635
+
636
+ ```typescript
637
+ function partial(
638
+ schema: z.ZodObject<T, z.core.$strip>,
639
+ ): z.ZodObject<{ [K in keyof T]: z.ZodOptional<T[K]> }, z.core.$strip>
640
+ ```
641
+
642
+ - `schema` — The Zod object schema to make partial.
643
+
644
+ **Returns:** A new Zod schema with all fields marked optional.
645
+
646
+ ##### `schema.pick(schema, keys)`
647
+
648
+ Creates a schema with only the specified fields, useful for create payloads
649
+ where only a subset of the full props should be provided by the client.
650
+
651
+ ```typescript
652
+ function pick(
653
+ schema: z.ZodObject<T, z.core.$strip>,
654
+ keys: readonly K[],
655
+ ): z.ZodObject<Pick<T, K>, z.core.$strip>
656
+ ```
657
+
658
+ - `schema` — The Zod object schema to pick from.
659
+ - `keys` — The field names to include in the new schema.
660
+
661
+ **Returns:** A new Zod schema containing only the picked fields.
550
662
 
551
663
  #### `types`
552
664
 
553
- Members:
665
+ Re-exported as a namespace — reach every member below through it (e.g. `types.<name>`).
666
+
667
+ ##### `types.BaseProps`
668
+
669
+ TypeScript type inferred from `basePropsSchema`, containing `id`, `createdAt`, and `updatedAt`.
670
+
671
+ ```typescript
672
+ type BaseProps = z.infer<typeof basePropsSchema>
673
+ ```
674
+
675
+ ##### `types.Props`
676
+
677
+ The resource's properties to be stored in the database.
678
+
679
+ Used by CRUD operations for type inference.
680
+
681
+ ```typescript
682
+ interface Props {
683
+ /**
684
+ * Usually a UUID.
685
+ */
686
+ id: string
687
+ /**
688
+ * When the resource was created.
689
+ *
690
+ * Usually an ISO 8601 timestamp.
691
+ */
692
+ createdAt: string
693
+ /**
694
+ * When the resource was last updated.
695
+ *
696
+ * Usually an ISO 8601 timestamp.
697
+ */
698
+ updatedAt: string
699
+ }
700
+ ```
701
+
702
+ ##### `types.Resource`
554
703
 
555
- - `types.BaseProps` — type: TypeScript type inferred from `basePropsSchema`, containing `id`, `createdAt`, and `updatedAt`.
556
- - `types.Props` — interface: The resource's properties to be stored in the database.
557
- - `types.Resource` — interface: An object describing the resource.
558
- - `types.ZodResource` — interface: An object describing the resource with a Zod schema.
559
- - `types.Response` — interface: Standard response from resource operations.
704
+ An object describing the resource.
705
+
706
+ The schema can be a Zod schema (z.ZodTypeAny) for new code,
707
+ or any other schema type for backward compatibility.
708
+
709
+ ```typescript
710
+ interface Resource<T = unknown> {
711
+ /**
712
+ * The name of the resource.
713
+ *
714
+ * @example User
715
+ */
716
+ name: string
717
+ /**
718
+ * The database table name for the resource.
719
+ *
720
+ * @example users
721
+ */
722
+ tableName: string
723
+ /**
724
+ * The schema used when validating props.
725
+ *
726
+ * Can be a Zod schema (z.ZodTypeAny) or other schema formats.
727
+ */
728
+ schema: T
729
+ }
730
+ ```
731
+
732
+ ##### `types.ZodResource`
733
+
734
+ An object describing the resource with a Zod schema.
735
+
736
+ Use this type when you want to enforce Zod schema usage.
737
+
738
+ ```typescript
739
+ interface ZodResource<T extends z.ZodTypeAny = z.ZodTypeAny> {
740
+ name: string
741
+ tableName: string
742
+ schema: T
743
+ }
744
+ ```
745
+
746
+ ##### `types.Response`
747
+
748
+ Standard response from resource operations.
749
+
750
+ ```typescript
751
+ interface Response<T = unknown> {
752
+ /**
753
+ * HTTP status code to return.
754
+ */
755
+ statusCode: number
756
+ /**
757
+ * The response payload.
758
+ */
759
+ body:
760
+ | {
761
+ props?: T
762
+ error?: string
763
+ errorKey?: string
764
+ }
765
+ | T[]
766
+ }
767
+ ```
560
768
 
561
769
  #### `utilities`
562
770
 
563
- Members:
771
+ Re-exported as a namespace — reach every member below through it (e.g. `utilities.<name>`).
772
+
773
+ ##### `utilities.ZodError`
774
+
775
+ An Error-like class used to store Zod validation issues.
776
+
777
+ ```typescript
778
+ interface ZodError<T = unknown> extends $ZodError<T> {
779
+ /** @deprecated Use the `z.treeifyError(err)` function instead. */
780
+ format(): core.$ZodFormattedError<T>
781
+ format<U>(mapper: (issue: core.$ZodIssue) => U): core.$ZodFormattedError<T, U>
782
+ /** @deprecated Use the `z.treeifyError(err)` function instead. */
783
+ flatten(): core.$ZodFlattenedError<T>
784
+ flatten<U>(mapper: (issue: core.$ZodIssue) => U): core.$ZodFlattenedError<T, U>
785
+ /** @deprecated Push directly to `.issues` instead. */
786
+ addIssue(issue: core.$ZodIssue): void
787
+ /** @deprecated Push directly to `.issues` instead. */
788
+ addIssues(issues: core.$ZodIssue[]): void
789
+ /** @deprecated Check `err.issues.length === 0` instead. */
790
+ isEmpty: boolean
791
+ }
792
+ ```
793
+
794
+ ##### `utilities.ZodSchema`
795
+
796
+ ````typescript
797
+ interface ZodType<
798
+ out Output = unknown,
799
+ out Input = unknown,
800
+ out Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<
801
+ Output,
802
+ Input
803
+ >,
804
+ > extends core.$ZodType<Output, Input, Internals> {
805
+ def: Internals['def']
806
+ type: Internals['def']['type']
807
+ /** @deprecated Use `.def` instead. */
808
+ _def: Internals['def']
809
+ /** @deprecated Use `z.output<typeof schema>` instead. */
810
+ _output: Internals['output']
811
+ /** @deprecated Use `z.input<typeof schema>` instead. */
812
+ _input: Internals['input']
813
+ '~standard': ZodStandardSchemaWithJSON<this>
814
+ /** Converts this schema to a JSON Schema representation. */
815
+ toJSONSchema(params?: core.ToJSONSchemaParams): core.ZodStandardJSONSchemaPayload<this>
816
+ check(...checks: (core.CheckFn<core.output<this>> | core.$ZodCheck<core.output<this>>)[]): this
817
+ with(...checks: (core.CheckFn<core.output<this>> | core.$ZodCheck<core.output<this>>)[]): this
818
+ clone(
819
+ def?: Internals['def'],
820
+ params?: {
821
+ parent: boolean
822
+ },
823
+ ): this
824
+ register<R extends core.$ZodRegistry>(
825
+ registry: R,
826
+ ...meta: this extends R['_schema']
827
+ ? undefined extends R['_meta']
828
+ ? [core.$replace<R['_meta'], this>?]
829
+ : [core.$replace<R['_meta'], this>]
830
+ : ['Incompatible schema']
831
+ ): this
832
+ brand<T extends PropertyKey = PropertyKey, Dir extends 'in' | 'out' | 'inout' = 'out'>(
833
+ value?: T,
834
+ ): PropertyKey extends T ? this : core.$ZodBranded<this, T, Dir>
835
+ parse(data: unknown, params?: core.ParseContext<core.$ZodIssue>): core.output<this>
836
+ safeParse(
837
+ data: unknown,
838
+ params?: core.ParseContext<core.$ZodIssue>,
839
+ ): parse.ZodSafeParseResult<core.output<this>>
840
+ parseAsync(data: unknown, params?: core.ParseContext<core.$ZodIssue>): Promise<core.output<this>>
841
+ safeParseAsync(
842
+ data: unknown,
843
+ params?: core.ParseContext<core.$ZodIssue>,
844
+ ): Promise<parse.ZodSafeParseResult<core.output<this>>>
845
+ spa: (
846
+ data: unknown,
847
+ params?: core.ParseContext<core.$ZodIssue>,
848
+ ) => Promise<parse.ZodSafeParseResult<core.output<this>>>
849
+ encode(data: core.output<this>, params?: core.ParseContext<core.$ZodIssue>): core.input<this>
850
+ decode(data: core.input<this>, params?: core.ParseContext<core.$ZodIssue>): core.output<this>
851
+ encodeAsync(
852
+ data: core.output<this>,
853
+ params?: core.ParseContext<core.$ZodIssue>,
854
+ ): Promise<core.input<this>>
855
+ decodeAsync(
856
+ data: core.input<this>,
857
+ params?: core.ParseContext<core.$ZodIssue>,
858
+ ): Promise<core.output<this>>
859
+ safeEncode(
860
+ data: core.output<this>,
861
+ params?: core.ParseContext<core.$ZodIssue>,
862
+ ): parse.ZodSafeParseResult<core.input<this>>
863
+ safeDecode(
864
+ data: core.input<this>,
865
+ params?: core.ParseContext<core.$ZodIssue>,
866
+ ): parse.ZodSafeParseResult<core.output<this>>
867
+ safeEncodeAsync(
868
+ data: core.output<this>,
869
+ params?: core.ParseContext<core.$ZodIssue>,
870
+ ): Promise<parse.ZodSafeParseResult<core.input<this>>>
871
+ safeDecodeAsync(
872
+ data: core.input<this>,
873
+ params?: core.ParseContext<core.$ZodIssue>,
874
+ ): Promise<parse.ZodSafeParseResult<core.output<this>>>
875
+ refine<Ch extends (arg: core.output<this>) => unknown | Promise<unknown>>(
876
+ check: Ch,
877
+ params?: string | core.$ZodCustomParams,
878
+ ): Ch extends (arg: any) => arg is infer R ? this & ZodType<R, core.input<this>> : this
879
+ superRefine(
880
+ refinement: (
881
+ arg: core.output<this>,
882
+ ctx: core.$RefinementCtx<core.output<this>>,
883
+ ) => void | Promise<void>,
884
+ params?: core.$ZodSuperRefineParams,
885
+ ): this
886
+ overwrite(fn: (x: core.output<this>) => core.output<this>): this
887
+ optional(): ZodOptional<this>
888
+ exactOptional(): ZodExactOptional<this>
889
+ nonoptional(params?: string | core.$ZodNonOptionalParams): ZodNonOptional<this>
890
+ nullable(): ZodNullable<this>
891
+ nullish(): ZodOptional<ZodNullable<this>>
892
+ default(def: util.NoUndefined<core.output<this>>): ZodDefault<this>
893
+ default(def: () => util.NoUndefined<core.output<this>>): ZodDefault<this>
894
+ prefault(def: () => core.input<this>): ZodPrefault<this>
895
+ prefault(def: core.input<this>): ZodPrefault<this>
896
+ array(): ZodArray<this>
897
+ or<T extends core.SomeType>(option: T): ZodUnion<[this, T]>
898
+ and<T extends core.SomeType>(incoming: T): ZodIntersection<this, T>
899
+ transform<NewOut>(
900
+ transform: (
901
+ arg: core.output<this>,
902
+ ctx: core.$RefinementCtx<core.output<this>>,
903
+ ) => NewOut | Promise<NewOut>,
904
+ ): ZodPipe<this, ZodTransform<Awaited<NewOut>, core.output<this>>>
905
+ catch(def: core.output<this>): ZodCatch<this>
906
+ catch(def: (ctx: core.$ZodCatchCtx) => core.output<this>): ZodCatch<this>
907
+ pipe<T extends core.$ZodType<any, core.output<this>>>(
908
+ target: T | core.$ZodType<any, core.output<this>>,
909
+ ): ZodPipe<this, T>
910
+ readonly(): ZodReadonly<this>
911
+ /** Returns a new instance that has been registered in `z.globalRegistry` with the specified description */
912
+ describe(description: string): this
913
+ description?: string
914
+ /** Returns the metadata associated with this instance in `z.globalRegistry` */
915
+ meta(): core.$replace<core.GlobalMeta, this> | undefined
916
+ /** Returns a new instance that has been registered in `z.globalRegistry` with the specified metadata */
917
+ meta(data: core.$replace<core.GlobalMeta, this>): this
918
+ /** @deprecated Try safe-parsing `undefined` (this is what `isOptional` does internally):
919
+ *
920
+ * ```ts
921
+ * const schema = z.string().optional();
922
+ * const isOptional = schema.safeParse(undefined).success; // true
923
+ * ```
924
+ */
925
+ isOptional(): boolean
926
+ /**
927
+ * @deprecated Try safe-parsing `null` (this is what `isNullable` does internally):
928
+ *
929
+ * ```ts
930
+ * const schema = z.string().nullable();
931
+ * const isNullable = schema.safeParse(null).success; // true
932
+ * ```
933
+ */
934
+ isNullable(): boolean
935
+ apply<T>(fn: (schema: this) => T): T
936
+ }
937
+ ````
938
+
939
+ ##### `utilities.getValidProps`
940
+
941
+ Validates resource props against a Zod schema, returning typed valid props or throwing
942
+ a descriptive error with field-level messages prefixed by the resource name.
943
+
944
+ ```typescript
945
+ const getValidProps: <Props>({
946
+ name,
947
+ schema,
948
+ props,
949
+ }: {
950
+ name: string
951
+ schema: ZodSchema<Props>
952
+ props: unknown
953
+ }) => Props
954
+ ```
955
+
956
+ - `options` — Validation options.
957
+ - `options.name` — The resource name (used in error messages, e.g., `"User.email: Required"`).
958
+ - `options.schema` — The Zod schema to validate against.
959
+ - `options.props` — The raw props to validate.
960
+
961
+ **Returns:** The validated and typed props.
962
+
963
+ ##### `utilities.safeParse`
964
+
965
+ Validates data against a Zod schema without throwing, returning a discriminated union.
966
+
967
+ ```typescript
968
+ const safeParse: <T>(
969
+ schema: ZodSchema<T>,
970
+ data: unknown,
971
+ ) => { success: true; data: T } | { success: false; error: ZodError }
972
+ ```
973
+
974
+ - `schema` — The Zod schema to validate against.
975
+ - `data` — The raw data to validate.
976
+
977
+ **Returns:** `{ success: true, data }` on success, or `{ success: false, error }` with a ZodError.
978
+
979
+ ##### `utilities.validate`
980
+
981
+ Validates data against a Zod schema, throwing a ZodError on failure.
982
+
983
+ ```typescript
984
+ const validate: <T>(schema: ZodSchema<T>, data: unknown) => T
985
+ ```
986
+
987
+ - `schema` — The Zod schema to validate against.
988
+ - `data` — The raw data to validate.
989
+
990
+ **Returns:** The validated and typed data.
991
+
992
+ ##### `utilities.isEmail`
993
+
994
+ Basic regex for determining whether or not a string is an email address.
995
+
996
+ ```typescript
997
+ const isEmail: (string: string, strict?: boolean) => boolean
998
+ ```
999
+
1000
+ - `string` — The string.
1001
+ - `strict` — Whether strict.
1002
+
1003
+ **Returns:** Whether email.
1004
+
1005
+ ##### `utilities.isUuid`
1006
+
1007
+ Basic regex for determining whether or not a string is a UUID.
1008
+
1009
+ ```typescript
1010
+ const isUuid: (uuid: string) => boolean
1011
+ ```
1012
+
1013
+ - `uuid` — The uuid.
564
1014
 
565
- - `utilities.getValidProps` — const: Validates resource props against a Zod schema, returning typed valid props or throwing
566
- - `utilities.safeParse` — const: Validates data against a Zod schema without throwing, returning a discriminated union.
567
- - `utilities.validate` — const: Validates data against a Zod schema, throwing a ZodError on failure.
568
- - `utilities.ZodError` — interface: An Error-like class used to store Zod validation issues.
569
- - `utilities.ZodSchema` — interface
570
- - `utilities.isEmail` — const: Basic regex for determining whether or not a string is an email address.
571
- - `utilities.isUuid` — const: Basic regex for determining whether or not a string is a UUID.
1015
+ **Returns:** Whether uuid.
572
1016
 
573
1017
  ## Injection Notes
574
1018
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/api-resource",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Resource CRUD operations and utilities for molecule.dev.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -39,13 +39,13 @@
39
39
  "zod": "4.4.3"
40
40
  },
41
41
  "devDependencies": {
42
- "@molecule/api-bond": "1.0.1",
43
- "@molecule/api-database": "1.0.1",
44
- "@molecule/api-locales-resource": "1.0.1",
45
- "@molecule/api-utilities-validation": "1.0.1",
42
+ "@molecule/api-bond": "1.0.2",
43
+ "@molecule/api-database": "1.1.1",
44
+ "@molecule/api-locales-resource": "1.0.2",
45
+ "@molecule/api-utilities-validation": "1.0.2",
46
46
  "@types/node": "26.1.2",
47
47
  "typescript": "6.0.3",
48
- "vitest": "4.1.10"
48
+ "vitest": "4.1.11"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "@molecule/api-bond": "^1.0.1",
@@ -59,7 +59,7 @@
59
59
  "url": "https://github.com/molecule-dev/molecule.git",
60
60
  "directory": "packages/api/infrastructure/resource"
61
61
  },
62
- "homepage": "https://github.com/molecule-dev/molecule/tree/main/packages/api/infrastructure/resource",
62
+ "homepage": "https://www.molecule.dev/packages/api-resource",
63
63
  "bugs": "https://github.com/molecule-dev/molecule/issues",
64
64
  "publishConfig": {
65
65
  "access": "public"