@molecule/api-resource 1.0.5 → 1.0.7

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 (2) hide show
  1. package/README.md +69 -172
  2. package/package.json +8 -8
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-10-17T04:45:43.913Z
6
+ Generated: 2026-10-26T04:23:42.740Z
7
7
  -->
8
8
 
9
9
  # @molecule/api-resource
@@ -307,11 +307,14 @@ export const create = ({ name, tableName, schema }: types.Resource) => {
307
307
  ```
308
308
 
309
309
  ```typescript
310
- function create({
310
+ function create<
311
+ CreateProps extends Record<string, unknown> = Record<string, unknown>,
312
+ CreatedProps extends types.Props & CreateProps = types.Props & CreateProps,
313
+ >({
311
314
  name,
312
315
  tableName,
313
316
  schema,
314
- }: types.Resource<unknown>): ({
317
+ }: types.Resource): ({
315
318
  props: createProps,
316
319
  id,
317
320
  }: {
@@ -372,7 +375,13 @@ export const del = ({ name, tableName, schema }: types.Resource) => {
372
375
  ```
373
376
 
374
377
  ```typescript
375
- function del({ name, tableName }: DeletedResource): ({ id }: { id: Props['id'] }) => Promise<
378
+ function del<
379
+ Props extends types.Props = types.Props,
380
+ DeletedResource extends types.Resource<Props> = types.Resource<Props>,
381
+ >({
382
+ name,
383
+ tableName,
384
+ }: DeletedResource): ({ id }: { id: Props['id'] }) => Promise<
376
385
  | { statusCode: number; body: { error: string; errorKey: string; props?: undefined } }
377
386
  | {
378
387
  statusCode: number
@@ -394,7 +403,10 @@ Creates a request handler to be used to query resources.
394
403
  Uses the bonded DataStore from `@molecule/api-database` for database-agnostic operations.
395
404
 
396
405
  ```typescript
397
- function query({
406
+ function query<
407
+ Props extends types.Props = types.Props,
408
+ QueriedResource extends types.Resource = types.Resource,
409
+ >({
398
410
  tableName,
399
411
  }: QueriedResource): (
400
412
  req: MoleculeRequest,
@@ -432,7 +444,10 @@ export const read = ({ name, tableName, schema }: types.Resource) => {
432
444
  ```
433
445
 
434
446
  ```typescript
435
- function read({
447
+ function read<
448
+ ReadProps extends types.Props = types.Props,
449
+ ReadResource extends types.Resource<ReadProps> = types.Resource<ReadProps>,
450
+ >({
436
451
  tableName,
437
452
  }: ReadResource): ({
438
453
  id,
@@ -504,11 +519,18 @@ export const update = ({ name, tableName, schema }: types.Resource) => {
504
519
  ```
505
520
 
506
521
  ```typescript
507
- function update({
522
+ function update<
523
+ UpdateProps extends Record<string, unknown> = Record<string, unknown>,
524
+ UpdatedProps extends Pick<types.Props, `updatedAt`> & UpdateProps = Pick<
525
+ types.Props,
526
+ `updatedAt`
527
+ > &
528
+ UpdateProps,
529
+ >({
508
530
  name,
509
531
  tableName,
510
532
  schema,
511
- }: types.Resource<unknown>): ({
533
+ }: types.Resource): ({
512
534
  id,
513
535
  props: updateProps,
514
536
  }: {
@@ -597,9 +619,7 @@ Creates a Zod schema for the standard `{ statusCode, body }` response
597
619
  returned by resource CRUD operations.
598
620
 
599
621
  ```typescript
600
- function responseSchema(
601
- propsSchema: T,
602
- ): z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>
622
+ function responseSchema<T extends z.ZodTypeAny>(propsSchema: T): z.ZodTypeAny
603
623
  ```
604
624
 
605
625
  - `propsSchema` — The Zod schema for the resource's props (e.g. `userPropsSchema`).
@@ -612,9 +632,7 @@ Creates a Zod schema that validates a resource descriptor object
612
632
  (`{ name, tableName, schema }`).
613
633
 
614
634
  ```typescript
615
- function resourceSchema(
616
- _propsSchema: T,
617
- ): z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>
635
+ function resourceSchema<T extends z.ZodTypeAny>(_propsSchema: T): z.ZodTypeAny
618
636
  ```
619
637
 
620
638
  - `_propsSchema` — The Zod schema for the resource's props (used for type inference only).
@@ -627,10 +645,7 @@ Validates data against a Zod schema, throwing an `Error` with a
627
645
  human-readable message listing all validation failures if invalid.
628
646
 
629
647
  ```typescript
630
- function validate(
631
- schema: z.ZodType<T, unknown, z.core.$ZodTypeInternals<T, unknown>>,
632
- data: unknown,
633
- ): T
648
+ function validate<T>(schema: z.ZodSchema<T>, data: unknown): T
634
649
  ```
635
650
 
636
651
  - `schema` — The Zod schema to validate against.
@@ -644,8 +659,8 @@ Validates data against a Zod schema without throwing. Returns a discriminated
644
659
  union: `{ success: true, data }` on success or `{ success: false, error }` on failure.
645
660
 
646
661
  ```typescript
647
- function safeParse(
648
- schema: z.ZodType<T, unknown, z.core.$ZodTypeInternals<T, unknown>>,
662
+ function safeParse<T>(
663
+ schema: z.ZodSchema<T>,
649
664
  data: unknown,
650
665
  ): { success: true; data: T } | { success: false; error: z.ZodError }
651
666
  ```
@@ -661,9 +676,9 @@ Creates a schema where all fields are optional, suitable for validating
661
676
  partial update payloads where only changed fields are sent.
662
677
 
663
678
  ```typescript
664
- function partial(
665
- schema: z.ZodObject<T, z.core.$strip>,
666
- ): z.ZodObject<{ [K in keyof T]: z.ZodOptional<T[K]> }, z.core.$strip>
679
+ function partial<T extends z.ZodRawShape>(
680
+ schema: z.ZodObject<T>,
681
+ ): z.ZodObject<{ [K in keyof T]: z.ZodOptional<T[K]> }>
667
682
  ```
668
683
 
669
684
  - `schema` — The Zod object schema to make partial.
@@ -676,10 +691,10 @@ Creates a schema with only the specified fields, useful for create payloads
676
691
  where only a subset of the full props should be provided by the client.
677
692
 
678
693
  ```typescript
679
- function pick(
680
- schema: z.ZodObject<T, z.core.$strip>,
694
+ function pick<T extends z.ZodRawShape, K extends keyof T>(
695
+ schema: z.ZodObject<T>,
681
696
  keys: readonly K[],
682
- ): z.ZodObject<Pick<T, K>, z.core.$strip>
697
+ ): z.ZodObject<Pick<T, K>>
683
698
  ```
684
699
 
685
700
  - `schema` — The Zod object schema to pick from.
@@ -797,6 +812,16 @@ interface Response<T = unknown> {
797
812
 
798
813
  Re-exported as a namespace — reach every member below through it (e.g. `utilities.<name>`).
799
814
 
815
+ ##### `utilities.ZodSchema` _(deprecated)_
816
+
817
+ ```typescript
818
+ type ZodSchema<
819
+ Output = unknown,
820
+ Input = unknown,
821
+ Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>,
822
+ > = ZodType<Output, Input, Internals>
823
+ ```
824
+
800
825
  ##### `utilities.ZodError`
801
826
 
802
827
  An Error-like class used to store Zod validation issues.
@@ -818,151 +843,6 @@ interface ZodError<T = unknown> extends $ZodError<T> {
818
843
  }
819
844
  ```
820
845
 
821
- ##### `utilities.ZodSchema`
822
-
823
- ````typescript
824
- interface ZodType<
825
- out Output = unknown,
826
- out Input = unknown,
827
- out Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<
828
- Output,
829
- Input
830
- >,
831
- > extends core.$ZodType<Output, Input, Internals> {
832
- def: Internals['def']
833
- type: Internals['def']['type']
834
- /** @deprecated Use `.def` instead. */
835
- _def: Internals['def']
836
- /** @deprecated Use `z.output<typeof schema>` instead. */
837
- _output: Internals['output']
838
- /** @deprecated Use `z.input<typeof schema>` instead. */
839
- _input: Internals['input']
840
- '~standard': ZodStandardSchemaWithJSON<this>
841
- /** Converts this schema to a JSON Schema representation. */
842
- toJSONSchema(params?: core.ToJSONSchemaParams): core.ZodStandardJSONSchemaPayload<this>
843
- check(...checks: (core.CheckFn<core.output<this>> | core.$ZodCheck<core.output<this>>)[]): this
844
- with(...checks: (core.CheckFn<core.output<this>> | core.$ZodCheck<core.output<this>>)[]): this
845
- clone(
846
- def?: Internals['def'],
847
- params?: {
848
- parent: boolean
849
- },
850
- ): this
851
- register<R extends core.$ZodRegistry>(
852
- registry: R,
853
- ...meta: this extends R['_schema']
854
- ? undefined extends R['_meta']
855
- ? [core.$replace<R['_meta'], this>?]
856
- : [core.$replace<R['_meta'], this>]
857
- : ['Incompatible schema']
858
- ): this
859
- brand<T extends PropertyKey = PropertyKey, Dir extends 'in' | 'out' | 'inout' = 'out'>(
860
- value?: T,
861
- ): PropertyKey extends T ? this : core.$ZodBranded<this, T, Dir>
862
- parse(data: unknown, params?: core.ParseContext<core.$ZodIssue>): core.output<this>
863
- safeParse(
864
- data: unknown,
865
- params?: core.ParseContext<core.$ZodIssue>,
866
- ): parse.ZodSafeParseResult<core.output<this>>
867
- parseAsync(data: unknown, params?: core.ParseContext<core.$ZodIssue>): Promise<core.output<this>>
868
- safeParseAsync(
869
- data: unknown,
870
- params?: core.ParseContext<core.$ZodIssue>,
871
- ): Promise<parse.ZodSafeParseResult<core.output<this>>>
872
- spa: (
873
- data: unknown,
874
- params?: core.ParseContext<core.$ZodIssue>,
875
- ) => Promise<parse.ZodSafeParseResult<core.output<this>>>
876
- encode(data: core.output<this>, params?: core.ParseContext<core.$ZodIssue>): core.input<this>
877
- decode(data: core.input<this>, params?: core.ParseContext<core.$ZodIssue>): core.output<this>
878
- encodeAsync(
879
- data: core.output<this>,
880
- params?: core.ParseContext<core.$ZodIssue>,
881
- ): Promise<core.input<this>>
882
- decodeAsync(
883
- data: core.input<this>,
884
- params?: core.ParseContext<core.$ZodIssue>,
885
- ): Promise<core.output<this>>
886
- safeEncode(
887
- data: core.output<this>,
888
- params?: core.ParseContext<core.$ZodIssue>,
889
- ): parse.ZodSafeParseResult<core.input<this>>
890
- safeDecode(
891
- data: core.input<this>,
892
- params?: core.ParseContext<core.$ZodIssue>,
893
- ): parse.ZodSafeParseResult<core.output<this>>
894
- safeEncodeAsync(
895
- data: core.output<this>,
896
- params?: core.ParseContext<core.$ZodIssue>,
897
- ): Promise<parse.ZodSafeParseResult<core.input<this>>>
898
- safeDecodeAsync(
899
- data: core.input<this>,
900
- params?: core.ParseContext<core.$ZodIssue>,
901
- ): Promise<parse.ZodSafeParseResult<core.output<this>>>
902
- refine<Ch extends (arg: core.output<this>) => unknown | Promise<unknown>>(
903
- check: Ch,
904
- params?: string | core.$ZodCustomParams,
905
- ): Ch extends (arg: any) => arg is infer R ? this & ZodType<R, core.input<this>> : this
906
- superRefine(
907
- refinement: (
908
- arg: core.output<this>,
909
- ctx: core.$RefinementCtx<core.output<this>>,
910
- ) => void | Promise<void>,
911
- params?: core.$ZodSuperRefineParams,
912
- ): this
913
- overwrite(fn: (x: core.output<this>) => core.output<this>): this
914
- optional(): ZodOptional<this>
915
- exactOptional(): ZodExactOptional<this>
916
- nonoptional(params?: string | core.$ZodNonOptionalParams): ZodNonOptional<this>
917
- nullable(): ZodNullable<this>
918
- nullish(): ZodOptional<ZodNullable<this>>
919
- default(def: util.NoUndefined<core.output<this>>): ZodDefault<this>
920
- default(def: () => util.NoUndefined<core.output<this>>): ZodDefault<this>
921
- prefault(def: () => core.input<this>): ZodPrefault<this>
922
- prefault(def: core.input<this>): ZodPrefault<this>
923
- array(): ZodArray<this>
924
- or<T extends core.SomeType>(option: T): ZodUnion<[this, T]>
925
- and<T extends core.SomeType>(incoming: T): ZodIntersection<this, T>
926
- transform<NewOut>(
927
- transform: (
928
- arg: core.output<this>,
929
- ctx: core.$RefinementCtx<core.output<this>>,
930
- ) => NewOut | Promise<NewOut>,
931
- ): ZodPipe<this, ZodTransform<Awaited<NewOut>, core.output<this>>>
932
- catch(def: core.output<this>): ZodCatch<this>
933
- catch(def: (ctx: core.$ZodCatchCtx) => core.output<this>): ZodCatch<this>
934
- pipe<T extends core.$ZodType<any, core.output<this>>>(
935
- target: T | core.$ZodType<any, core.output<this>>,
936
- ): ZodPipe<this, T>
937
- readonly(): ZodReadonly<this>
938
- /** Returns a new instance that has been registered in `z.globalRegistry` with the specified description */
939
- describe(description: string): this
940
- description?: string
941
- /** Returns the metadata associated with this instance in `z.globalRegistry` */
942
- meta(): core.$replace<core.GlobalMeta, this> | undefined
943
- /** Returns a new instance that has been registered in `z.globalRegistry` with the specified metadata */
944
- meta(data: core.$replace<core.GlobalMeta, this>): this
945
- /** @deprecated Try safe-parsing `undefined` (this is what `isOptional` does internally):
946
- *
947
- * ```ts
948
- * const schema = z.string().optional();
949
- * const isOptional = schema.safeParse(undefined).success; // true
950
- * ```
951
- */
952
- isOptional(): boolean
953
- /**
954
- * @deprecated Try safe-parsing `null` (this is what `isNullable` does internally):
955
- *
956
- * ```ts
957
- * const schema = z.string().nullable();
958
- * const isNullable = schema.safeParse(null).success; // true
959
- * ```
960
- */
961
- isNullable(): boolean
962
- apply<T>(fn: (schema: this) => T): T
963
- }
964
- ````
965
-
966
846
  ##### `utilities.getValidProps`
967
847
 
968
848
  Validates resource props against a Zod schema, returning typed valid props or throwing
@@ -974,8 +854,17 @@ const getValidProps: <Props>({
974
854
  schema,
975
855
  props,
976
856
  }: {
857
+ /**
858
+ * The name of the resource (used in error messages).
859
+ */
977
860
  name: string
861
+ /**
862
+ * The Zod schema used when validating props.
863
+ */
978
864
  schema: ZodSchema<Props>
865
+ /**
866
+ * The `props` to be validated.
867
+ */
979
868
  props: unknown
980
869
  }) => Props
981
870
  ```
@@ -995,7 +884,15 @@ Validates data against a Zod schema without throwing, returning a discriminated
995
884
  const safeParse: <T>(
996
885
  schema: ZodSchema<T>,
997
886
  data: unknown,
998
- ) => { success: true; data: T } | { success: false; error: ZodError }
887
+ ) =>
888
+ | {
889
+ success: true
890
+ data: T
891
+ }
892
+ | {
893
+ success: false
894
+ error: ZodError
895
+ }
999
896
  ```
1000
897
 
1001
898
  - `schema` — The Zod schema to validate against.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/api-resource",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
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.4",
43
+ "@molecule/api-database": "1.2.1",
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.4",
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",