@aws-amplify/data-schema 1.2.8 → 1.3.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.
Files changed (122) hide show
  1. package/dist/cjs/ClientSchema/Core/ClientCustomOperations.js +4 -0
  2. package/dist/cjs/ClientSchema/Core/ClientCustomOperations.js.map +1 -0
  3. package/dist/cjs/{MappedTypes/CustomOperations.js → ClientSchema/Core/ClientCustomType.js} +1 -1
  4. package/dist/cjs/ClientSchema/Core/ClientCustomType.js.map +1 -0
  5. package/dist/cjs/{ClientSchema.js → ClientSchema/Core/ClientEnum.js} +1 -1
  6. package/dist/cjs/ClientSchema/Core/ClientEnum.js.map +1 -0
  7. package/dist/cjs/ClientSchema/Core/ClientModel.js +4 -0
  8. package/dist/cjs/ClientSchema/Core/ClientModel.js.map +1 -0
  9. package/dist/cjs/ClientSchema/Core/ClientSchemaProperty.js +4 -0
  10. package/dist/cjs/ClientSchema/Core/ClientSchemaProperty.js.map +1 -0
  11. package/dist/cjs/ClientSchema/Core/index.js +4 -0
  12. package/dist/cjs/ClientSchema/Core/index.js.map +1 -0
  13. package/dist/cjs/ClientSchema/index.js +4 -0
  14. package/dist/cjs/ClientSchema/index.js.map +1 -0
  15. package/dist/cjs/ClientSchema/utilities/ExtractNestedTypes.js +4 -0
  16. package/dist/cjs/ClientSchema/utilities/ExtractNestedTypes.js.map +1 -0
  17. package/dist/cjs/ClientSchema/utilities/ResolveField.js +4 -0
  18. package/dist/cjs/ClientSchema/utilities/ResolveField.js.map +1 -0
  19. package/dist/cjs/ClientSchema/utilities/ResolveRef.js +4 -0
  20. package/dist/cjs/ClientSchema/utilities/ResolveRef.js.map +1 -0
  21. package/dist/cjs/ClientSchema/utilities/SchemaMetadata.js +4 -0
  22. package/dist/cjs/ClientSchema/utilities/SchemaMetadata.js.map +1 -0
  23. package/dist/cjs/ClientSchema/utilities/index.js +9 -0
  24. package/dist/cjs/ClientSchema/utilities/index.js.map +1 -0
  25. package/dist/cjs/util/Filters.js +10 -0
  26. package/dist/cjs/util/Filters.js.map +1 -0
  27. package/dist/cjs/util/IndexShapes.js +4 -0
  28. package/dist/cjs/util/IndexShapes.js.map +1 -0
  29. package/dist/cjs/util/Select.js +4 -0
  30. package/dist/cjs/util/Select.js.map +1 -0
  31. package/dist/esm/Authorization.d.ts +3 -3
  32. package/dist/esm/ClientSchema/Core/ClientCustomOperations.d.ts +88 -0
  33. package/dist/esm/ClientSchema/Core/ClientCustomOperations.mjs +2 -0
  34. package/dist/esm/ClientSchema/Core/ClientCustomOperations.mjs.map +1 -0
  35. package/dist/esm/ClientSchema/Core/ClientCustomType.d.ts +7 -0
  36. package/dist/esm/ClientSchema/Core/ClientCustomType.mjs +2 -0
  37. package/dist/esm/ClientSchema/Core/ClientCustomType.mjs.map +1 -0
  38. package/dist/esm/ClientSchema/Core/ClientEnum.d.ts +5 -0
  39. package/dist/esm/ClientSchema/Core/ClientEnum.mjs +2 -0
  40. package/dist/esm/ClientSchema/Core/ClientEnum.mjs.map +1 -0
  41. package/dist/esm/ClientSchema/Core/ClientModel.d.ts +123 -0
  42. package/dist/esm/ClientSchema/Core/ClientModel.mjs +2 -0
  43. package/dist/esm/ClientSchema/Core/ClientModel.mjs.map +1 -0
  44. package/dist/esm/ClientSchema/Core/ClientSchemaProperty.d.ts +4 -0
  45. package/dist/esm/ClientSchema/Core/ClientSchemaProperty.mjs +2 -0
  46. package/dist/esm/ClientSchema/Core/ClientSchemaProperty.mjs.map +1 -0
  47. package/dist/esm/ClientSchema/Core/index.d.ts +5 -0
  48. package/dist/esm/ClientSchema/Core/index.mjs +2 -0
  49. package/dist/esm/ClientSchema/Core/index.mjs.map +1 -0
  50. package/dist/esm/ClientSchema/index.d.ts +59 -0
  51. package/dist/esm/ClientSchema/index.mjs +2 -0
  52. package/dist/esm/ClientSchema/index.mjs.map +1 -0
  53. package/dist/esm/ClientSchema/utilities/ExtractNestedTypes.d.ts +7 -0
  54. package/dist/esm/ClientSchema/utilities/ExtractNestedTypes.mjs +2 -0
  55. package/dist/esm/ClientSchema/utilities/ExtractNestedTypes.mjs.map +1 -0
  56. package/dist/esm/ClientSchema/utilities/ResolveField.d.ts +29 -0
  57. package/dist/esm/ClientSchema/utilities/ResolveField.mjs +2 -0
  58. package/dist/esm/ClientSchema/utilities/ResolveField.mjs.map +1 -0
  59. package/dist/esm/ClientSchema/utilities/ResolveRef.d.ts +18 -0
  60. package/dist/esm/ClientSchema/utilities/ResolveRef.mjs +2 -0
  61. package/dist/esm/ClientSchema/utilities/ResolveRef.mjs.map +1 -0
  62. package/dist/esm/ClientSchema/utilities/SchemaMetadata.d.ts +7 -0
  63. package/dist/esm/ClientSchema/utilities/SchemaMetadata.mjs +2 -0
  64. package/dist/esm/ClientSchema/utilities/SchemaMetadata.mjs.map +1 -0
  65. package/dist/esm/ClientSchema/utilities/index.d.ts +4 -0
  66. package/dist/esm/ClientSchema/utilities/index.mjs +2 -0
  67. package/dist/esm/ClientSchema/utilities/index.mjs.map +1 -0
  68. package/dist/esm/MappedTypes/ImplicitFieldInjector.d.ts +1 -1
  69. package/dist/esm/MappedTypes/ModelMetadata.d.ts +1 -1
  70. package/dist/esm/MappedTypes/ResolveFieldProperties.d.ts +1 -1
  71. package/dist/esm/ModelSchema.d.ts +11 -5
  72. package/dist/esm/ModelType.d.ts +9 -8
  73. package/dist/esm/ModelType.mjs.map +1 -1
  74. package/dist/esm/runtime/client/index.d.ts +77 -223
  75. package/dist/esm/runtime/internals/generateCustomOperationsProperty.d.ts +12 -5
  76. package/dist/esm/util/Filters.d.ts +94 -0
  77. package/dist/esm/util/Filters.mjs +2 -0
  78. package/dist/esm/util/Filters.mjs.map +1 -0
  79. package/dist/esm/util/IndexShapes.d.ts +13 -0
  80. package/dist/esm/util/IndexShapes.mjs +2 -0
  81. package/dist/esm/util/IndexShapes.mjs.map +1 -0
  82. package/dist/esm/util/Select.d.ts +3 -0
  83. package/dist/esm/util/Select.mjs +2 -0
  84. package/dist/esm/util/Select.mjs.map +1 -0
  85. package/dist/esm/util/index.d.ts +3 -0
  86. package/dist/meta/cjs.tsbuildinfo +1 -1
  87. package/package.json +1 -1
  88. package/src/Authorization.ts +2 -2
  89. package/src/ClientSchema/Core/ClientCustomOperations.ts +152 -0
  90. package/src/ClientSchema/Core/ClientCustomType.ts +11 -0
  91. package/src/ClientSchema/Core/ClientEnum.ts +7 -0
  92. package/src/ClientSchema/Core/ClientModel.ts +299 -0
  93. package/src/ClientSchema/Core/ClientSchemaProperty.ts +10 -0
  94. package/src/ClientSchema/Core/index.ts +5 -0
  95. package/src/ClientSchema/index.ts +158 -0
  96. package/src/ClientSchema/utilities/ExtractNestedTypes.ts +15 -0
  97. package/src/ClientSchema/utilities/ResolveField.ts +79 -0
  98. package/src/ClientSchema/utilities/ResolveRef.ts +38 -0
  99. package/src/ClientSchema/utilities/SchemaMetadata.ts +11 -0
  100. package/src/ClientSchema/utilities/index.ts +4 -0
  101. package/src/MappedTypes/ImplicitFieldInjector.ts +1 -1
  102. package/src/MappedTypes/ModelMetadata.ts +2 -1
  103. package/src/MappedTypes/ResolveFieldProperties.ts +1 -1
  104. package/src/ModelSchema.ts +19 -4
  105. package/src/ModelType.ts +12 -3
  106. package/src/runtime/client/index.ts +175 -433
  107. package/src/runtime/internals/generateCustomOperationsProperty.ts +2 -2
  108. package/src/runtime/internals/utils/clientProperties/generateEnumsProperty.ts +1 -1
  109. package/src/util/Filters.ts +102 -0
  110. package/src/util/IndexShapes.ts +10 -0
  111. package/src/util/Select.ts +3 -0
  112. package/src/util/index.ts +3 -0
  113. package/dist/cjs/ClientSchema.js.map +0 -1
  114. package/dist/cjs/MappedTypes/CustomOperations.js.map +0 -1
  115. package/dist/esm/ClientSchema.d.ts +0 -51
  116. package/dist/esm/ClientSchema.mjs +0 -2
  117. package/dist/esm/ClientSchema.mjs.map +0 -1
  118. package/dist/esm/MappedTypes/CustomOperations.d.ts +0 -125
  119. package/dist/esm/MappedTypes/CustomOperations.mjs +0 -2
  120. package/dist/esm/MappedTypes/CustomOperations.mjs.map +0 -1
  121. package/src/ClientSchema.ts +0 -121
  122. package/src/MappedTypes/CustomOperations.ts +0 -254
@@ -1,17 +1,24 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import {
4
- DeepReadOnlyObject,
5
- UnwrapArray,
6
- UnionToIntersection,
7
- Prettify,
8
- Equal,
4
+ type DeepReadOnlyObject,
5
+ type UnwrapArray,
6
+ type UnionToIntersection,
7
+ type Prettify,
9
8
  __modelMeta__,
10
- ExtractModelMeta,
11
- IsEmptyStringOrNever,
12
9
  } from '@aws-amplify/data-schema-types';
13
10
  import type { Observable } from 'rxjs';
14
- import { deferredRefResolvingPrefix } from '../../ModelType';
11
+ import type {
12
+ ClientSchemaByEntityType,
13
+ ClientSchemaByEntityTypeBaseShape,
14
+ } from '../../ClientSchema';
15
+ import type { ExtractNestedTypes } from '../../ClientSchema/utilities/';
16
+ import type {
17
+ Select,
18
+ StringFilter,
19
+ NumericFilter,
20
+ BooleanFilters,
21
+ } from '../../util';
15
22
 
16
23
  // temporarily export symbols from `data-schema-types` because in case part of the
17
24
  // problem with the runtime -> data-schema migration comes down to a mismatch
@@ -42,18 +49,31 @@ type NonRelationalFields<M extends Model> = {
42
49
  : Field]: M[Field];
43
50
  };
44
51
 
52
+ type WithOptionalsAsNullishOnly<T> =
53
+ T extends Array<infer ArrayType>
54
+ ? Array<WithOptionalsAsNullishOnly<ArrayType>>
55
+ : T extends (...args: any) => any
56
+ ? T
57
+ : T extends object
58
+ ? {
59
+ [K in keyof T]-?: WithOptionalsAsNullishOnly<T[K]>;
60
+ }
61
+ : Exclude<T, undefined>;
62
+
45
63
  /**
46
64
  * Selection set-aware CRUDL operation return value type
47
65
  *
48
- * @returns model type as-is with default selection set; otherwise generates return type from custonm sel. set
66
+ * @returns model type with default selection set; otherwise generates return type from custom sel. set. Optionality is removed from both return types.
49
67
  */
50
68
  type ReturnValue<
51
- M extends Model,
69
+ M extends ClientSchemaByEntityTypeBaseShape['models'][string],
52
70
  FlatModel extends Model,
53
71
  Paths extends ReadonlyArray<ModelPath<FlatModel>>,
54
72
  > = Paths extends undefined | never[]
55
- ? M
56
- : CustomSelectionSetReturnValue<FlatModel, Paths[number]>;
73
+ ? WithOptionalsAsNullishOnly<M['type']>
74
+ : WithOptionalsAsNullishOnly<
75
+ CustomSelectionSetReturnValue<FlatModel, Paths[number]>
76
+ >;
57
77
 
58
78
  /**
59
79
  * This mapped type traverses the SelectionSetReturnValue result and the original FlatModel, restoring array types
@@ -241,8 +261,7 @@ export type ModelPath<
241
261
  *
242
262
  * ```
243
263
  */
244
- // TODO: temporarily exported for troubleshooting
245
- export type ResolvedModel<
264
+ type ResolvedModel<
246
265
  Model extends Record<string, unknown>,
247
266
  Depth extends number = 7,
248
267
  RecursionLoop extends number[] = [-1, 0, 1, 2, 3, 4, 5, 6],
@@ -267,54 +286,9 @@ export type SelectionSet<
267
286
  Model extends Record<string, unknown>,
268
287
  Path extends ReadonlyArray<ModelPath<FlatModel>>,
269
288
  FlatModel extends Record<string, unknown> = ResolvedModel<Model>,
270
- > = CustomSelectionSetReturnValue<FlatModel, Path[number]>;
271
- // #endregion
272
-
273
- // #region Input mapped types
274
-
275
- export type ModelIdentifier<ModelMeta extends ModelMetaShape> =
276
- ModelMeta['identifier']['pk'] &
277
- (ModelMeta['identifier']['sk'] extends never
278
- ? unknown // unknown collapses in an intersection
279
- : ModelMeta['identifier']['sk']);
280
-
281
- type IfEquals<X, Y, A = X, B = never> =
282
- (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? A : B;
283
-
284
- // Excludes readonly fields from Record type
285
- type WritableKeys<T> = {
286
- [P in keyof T]-?: IfEquals<
287
- { [Q in P]: T[P] },
288
- { -readonly [Q in P]: T[P] },
289
- P
290
- >;
291
- }[keyof T];
292
-
293
- /**
294
- * All required fields and relational fields, exclude readonly fields
295
- */
296
- type MutationInput<
297
- Fields,
298
- WritableFields = Pick<Fields, WritableKeys<Fields>>,
299
- > = {
300
- [Prop in keyof WritableFields as WritableFields[Prop] extends (
301
- ...args: any
302
- ) => any
303
- ? never
304
- : Prop]: WritableFields[Prop];
305
- };
306
-
307
- /**
308
- * All identifiers and fields used to create a model
309
- */
310
- type CreateModelInput<
311
- Model extends Record<string, unknown>,
312
- ModelMeta extends ModelMetaShape,
313
- > =
314
- Equal<ModelIdentifier<ModelMeta>, { id: string }> extends true
315
- ? Partial<ModelIdentifier<ModelMeta>> & Omit<MutationInput<Model>, 'id'>
316
- : MutationInput<Model>;
317
-
289
+ > = WithOptionalsAsNullishOnly<
290
+ CustomSelectionSetReturnValue<FlatModel, Path[number]>
291
+ >;
318
292
  // #endregion
319
293
 
320
294
  // #region Interfaces copied from `graphql` package
@@ -393,7 +367,7 @@ export type ObserveQueryReturnValue<T> = Observable<{
393
367
  isSynced: boolean;
394
368
  }>;
395
369
 
396
- export type LazyLoader<Model, IsArray extends boolean> = (
370
+ export type LazyLoader<T, IsArray extends boolean> = (
397
371
  options?: IsArray extends true
398
372
  ? {
399
373
  authMode?: AuthMode;
@@ -408,8 +382,8 @@ export type LazyLoader<Model, IsArray extends boolean> = (
408
382
  headers?: CustomHeaders;
409
383
  },
410
384
  ) => IsArray extends true
411
- ? ListReturnValue<Prettify<NonNullable<Model>>>
412
- : SingularReturnValue<Prettify<Model>>;
385
+ ? ListReturnValue<Prettify<NonNullable<T>>>
386
+ : SingularReturnValue<Prettify<T>>;
413
387
 
414
388
  export type AuthMode =
415
389
  | 'apiKey'
@@ -420,169 +394,100 @@ export type AuthMode =
420
394
  | 'lambda'
421
395
  | 'none';
422
396
 
423
- type LogicalFilters<Model extends Record<any, any>> = {
397
+ type LogicalFilters<
398
+ Model extends ClientSchemaByEntityTypeBaseShape['models'][string],
399
+ > = {
424
400
  and?: ModelFilter<Model> | ModelFilter<Model>[];
425
401
  or?: ModelFilter<Model> | ModelFilter<Model>[];
426
402
  not?: ModelFilter<Model>;
427
403
  };
428
404
 
429
- /**
430
- * Filter options that can be used on fields where size checks are supported.
431
- */
432
- type SizeFilter = {
433
- between?: [number, number];
434
- eq?: number;
435
- ge?: number;
436
- gt?: number;
437
- le?: number;
438
- lt?: number;
439
- ne?: number;
440
- };
441
-
442
- /**
443
- * Not actually sure if/how customer can pass this through as variables yet.
444
- * Leaving it out for now:
445
- *
446
- * attributeType: "binary" | "binarySet" | "bool" | "list" | "map" | "number" | "numberSet" | "string" | "stringSet" | "_null"
447
- */
448
-
449
- /**
450
- * Filters options that can be used on string-like fields.
451
- */
452
- export type StringFilter<T extends string = string> = {
453
- attributeExists?: boolean;
454
- beginsWith?: string;
455
- between?: [string, string];
456
- contains?: string;
457
- eq?: T;
458
- ge?: string;
459
- gt?: string;
460
- le?: string;
461
- lt?: string;
462
- ne?: T;
463
- notContains?: string;
464
- size?: SizeFilter;
465
- };
466
-
467
- export type NumericFilter = {
468
- attributeExists?: boolean;
469
- between?: [number, number];
470
- eq?: number;
471
- ge?: number;
472
- gt?: number;
473
- le?: number;
474
- lt?: number;
475
- ne?: number;
476
- };
477
-
478
- type BooleanFilters = {
479
- attributeExists?: boolean;
480
- eq?: boolean;
481
- ne?: boolean;
482
- };
483
-
484
- /**
485
- * A composite SK (in an identifier or secondaryIndex) resolves to this type for
486
- * list queries and index queries
487
- *
488
- * @example
489
- * Given
490
- * ```ts
491
- * MyModel: a
492
- .model({
493
- pk: a.string().required(),
494
- sk1: a.string().required(),
495
- sk2: a.integer().required(),
496
- })
497
- .identifier(['pk', 'sk1', 'sk2']),
498
- * ```
499
- * Expected list options:
500
- * ```ts
501
- * {
502
- * pk?: string
503
- * sk1Sk2?: ModelPrimaryCompositeKeyConditionInput
504
- * }
505
- * ```
506
- * Where ModelPrimaryCompositeKeyConditionInput resolves to:
507
- * ```ts
508
- * {
509
- * eq: {sk1: string; sk2: number};
510
- * le: {sk1: string; sk2: number};
511
- * lt: {sk1: string; sk2: number};
512
- * ge: {sk1: string; sk2: number};
513
- * gt: {sk1: string; sk2: number};
514
- * between: [ {sk1: string; sk2: number} ];
515
- * beginsWith: {sk1: string; sk2: number};
516
- * }
517
- * ```
518
- * */
519
- export type ModelPrimaryCompositeKeyInput<
520
- SkIr extends Record<string, string | number>,
521
- > = {
522
- eq?: SkIr;
523
- le?: SkIr;
524
- lt?: SkIr;
525
- ge?: SkIr;
526
- gt?: SkIr;
527
- between?: [SkIr];
528
- beginsWith?: SkIr;
529
- };
530
-
531
- type ModelFilter<Model extends Record<any, any>> = LogicalFilters<Model> & {
532
- [K in keyof Model as Model[K] extends LazyLoader<any, any>
405
+ type ModelFilter<
406
+ Model extends ClientSchemaByEntityTypeBaseShape['models'][string],
407
+ > = LogicalFilters<Model> & {
408
+ [K in keyof Model['type'] as Model['type'][K] extends LazyLoader<any, any>
533
409
  ? never
534
- : K]?: boolean extends Model[K]
410
+ : K]?: boolean extends Model['type'][K]
535
411
  ? BooleanFilters
536
- : number extends Model[K]
412
+ : number extends Model['type'][K]
537
413
  ? NumericFilter
538
414
  : StringFilter;
539
415
  };
540
416
 
541
417
  export type ModelSortDirection = 'ASC' | 'DESC';
542
418
 
543
- type ModelMetaShape = {
544
- secondaryIndexes: SecondaryIndexIrShape[];
545
- identifier: PrimaryIndexIrShape;
419
+ type ListCpkOptions<
420
+ Model extends ClientSchemaByEntityTypeBaseShape['models'][string],
421
+ > = unknown extends Model['__meta']['listOptionsPkParams']
422
+ ? unknown
423
+ : Model['__meta']['listOptionsPkParams'] & {
424
+ sortDirection?: ModelSortDirection;
425
+ };
426
+
427
+ interface ClientSecondaryIndexField {
428
+ input: object;
429
+ }
430
+
431
+ type IndexQueryMethods<
432
+ Model extends ClientSchemaByEntityTypeBaseShape['models'][string],
433
+ > = {
434
+ [K in keyof Select<
435
+ Model['secondaryIndexes'],
436
+ ClientSecondaryIndexField
437
+ >]: IndexQueryMethod<
438
+ Model,
439
+ Select<Model['secondaryIndexes'], ClientSecondaryIndexField>[K]
440
+ >;
546
441
  };
547
442
 
548
- export type ModelTypesClient<
549
- ModelName extends string,
550
- Model extends Record<string, unknown>,
551
- ModelMeta extends ModelMetaShape,
552
- Enums extends Record<string, string>,
553
- FlatModel extends Record<string, unknown> = ResolvedModel<Model>,
554
- > = IndexQueryMethodsFromIR<
555
- ModelMeta['secondaryIndexes'],
556
- ModelName,
557
- Model,
558
- Enums
559
- > & {
443
+ type IndexQueryMethod<
444
+ Model extends ClientSchemaByEntityTypeBaseShape['models'][string],
445
+ Method extends ClientSecondaryIndexField,
446
+ FlatModel extends Record<string, unknown> = ResolvedModel<Model['type']>,
447
+ > = <SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(
448
+ input: Method['input'],
449
+ options?: {
450
+ filter?: ModelFilter<Model>;
451
+ sortDirection?: ModelSortDirection;
452
+ limit?: number;
453
+ nextToken?: string | null;
454
+ selectionSet?: SelectionSet;
455
+ authMode?: AuthMode;
456
+ authToken?: string;
457
+ headers?: CustomHeaders;
458
+ },
459
+ ) => ListReturnValue<Prettify<ReturnValue<Model, FlatModel, SelectionSet>>>;
460
+
461
+ type ModelTypesClient<
462
+ Model extends ClientSchemaByEntityTypeBaseShape['models'][string],
463
+ FlatModel extends Record<string, unknown> = ResolvedModel<Model['type']>,
464
+ > = IndexQueryMethods<Model> & {
560
465
  create: (
561
- model: Prettify<CreateModelInput<Model, ModelMeta>>,
466
+ model: Model['createType'],
562
467
  options?: {
563
468
  authMode?: AuthMode;
564
469
  authToken?: string;
565
470
  headers?: CustomHeaders;
566
471
  },
567
- ) => SingularReturnValue<Model>;
472
+ ) => SingularReturnValue<Model['type']>;
568
473
  update: (
569
- model: Prettify<ModelIdentifier<ModelMeta> & Partial<MutationInput<Model>>>,
474
+ model: Model['updateType'],
570
475
  options?: {
571
476
  authMode?: AuthMode;
572
477
  authToken?: string;
573
478
  headers?: CustomHeaders;
574
479
  },
575
- ) => SingularReturnValue<Model>;
480
+ ) => SingularReturnValue<Model['type']>;
576
481
  delete: (
577
- identifier: ModelIdentifier<ModelMeta>,
482
+ identifier: Model['deleteType'],
578
483
  options?: {
579
484
  authMode?: AuthMode;
580
485
  authToken?: string;
581
486
  headers?: CustomHeaders;
582
487
  },
583
- ) => SingularReturnValue<Model>;
488
+ ) => SingularReturnValue<Model['type']>;
584
489
  get<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(
585
- identifier: ModelIdentifier<ModelMeta>,
490
+ identifier: Model['identifier'],
586
491
  options?: {
587
492
  selectionSet?: SelectionSet;
588
493
  authMode?: AuthMode;
@@ -591,7 +496,7 @@ export type ModelTypesClient<
591
496
  },
592
497
  ): SingularReturnValue<Prettify<ReturnValue<Model, FlatModel, SelectionSet>>>;
593
498
  list<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(
594
- options?: ListPkOptions<ModelMeta, Enums> & {
499
+ options?: ListCpkOptions<Model> & {
595
500
  filter?: ModelFilter<Model>;
596
501
  limit?: number;
597
502
  nextToken?: string | null;
@@ -647,19 +552,11 @@ export type ModelTypesClient<
647
552
  };
648
553
 
649
554
  type ModelTypesSSRCookies<
650
- ModelName extends string,
651
- Model extends Record<string, unknown>,
652
- ModelMeta extends ModelMetaShape,
653
- Enums extends Record<string, string>,
654
- FlatModel extends Record<string, unknown> = ResolvedModel<Model>,
655
- > = IndexQueryMethodsFromIR<
656
- ModelMeta['secondaryIndexes'],
657
- ModelName,
658
- Model,
659
- Enums
660
- > & {
555
+ Model extends ClientSchemaByEntityTypeBaseShape['models'][string],
556
+ FlatModel extends Record<string, unknown> = ResolvedModel<Model['type']>,
557
+ > = IndexQueryMethods<Model> & {
661
558
  create: (
662
- model: Prettify<CreateModelInput<Model, ModelMeta>>,
559
+ model: Model['createType'],
663
560
  options?: {
664
561
  authMode?: AuthMode;
665
562
  authToken?: string;
@@ -667,7 +564,7 @@ type ModelTypesSSRCookies<
667
564
  },
668
565
  ) => SingularReturnValue<Model>;
669
566
  update: (
670
- model: Prettify<ModelIdentifier<ModelMeta> & Partial<MutationInput<Model>>>,
567
+ model: Model['updateType'],
671
568
  options?: {
672
569
  authMode?: AuthMode;
673
570
  authToken?: string;
@@ -675,7 +572,7 @@ type ModelTypesSSRCookies<
675
572
  },
676
573
  ) => SingularReturnValue<Model>;
677
574
  delete: (
678
- identifier: ModelIdentifier<ModelMeta>,
575
+ identifier: Model['deleteType'],
679
576
  options?: {
680
577
  authMode?: AuthMode;
681
578
  authToken?: string;
@@ -683,7 +580,7 @@ type ModelTypesSSRCookies<
683
580
  },
684
581
  ) => SingularReturnValue<Model>;
685
582
  get<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(
686
- identifier: ModelIdentifier<ModelMeta>,
583
+ identifier: Model['identifier'],
687
584
  options?: {
688
585
  selectionSet?: SelectionSet;
689
586
  authMode?: AuthMode;
@@ -692,7 +589,7 @@ type ModelTypesSSRCookies<
692
589
  },
693
590
  ): SingularReturnValue<Prettify<ReturnValue<Model, FlatModel, SelectionSet>>>;
694
591
  list<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(
695
- options?: ListPkOptions<ModelMeta, Enums> & {
592
+ options?: ListCpkOptions<Model> & {
696
593
  filter?: ModelFilter<Model>;
697
594
  sortDirection?: ModelSortDirection;
698
595
  limit?: number;
@@ -706,21 +603,13 @@ type ModelTypesSSRCookies<
706
603
  };
707
604
 
708
605
  type ModelTypesSSRRequest<
709
- ModelName extends string,
710
- Model extends Record<string, unknown>,
711
- ModelMeta extends ModelMetaShape,
712
- Enums extends Record<string, string>,
713
- FlatModel extends Record<string, unknown> = ResolvedModel<Model>,
714
- > = IndexQueryMethodsFromIR<
715
- ModelMeta['secondaryIndexes'],
716
- ModelName,
717
- Model,
718
- Enums
719
- > & {
606
+ Model extends ClientSchemaByEntityTypeBaseShape['models'][string],
607
+ FlatModel extends Record<string, unknown> = ResolvedModel<Model['type']>,
608
+ > = IndexQueryMethods<Model> & {
720
609
  create: (
721
610
  // TODO: actual type
722
611
  contextSpec: any,
723
- model: Prettify<CreateModelInput<Model, ModelMeta>>,
612
+ model: Model['createType'],
724
613
  options?: {
725
614
  authMode?: AuthMode;
726
615
  authToken?: string;
@@ -729,7 +618,7 @@ type ModelTypesSSRRequest<
729
618
  ) => SingularReturnValue<Model>;
730
619
  update: (
731
620
  contextSpec: any,
732
- model: Prettify<ModelIdentifier<ModelMeta> & Partial<MutationInput<Model>>>,
621
+ model: Model['updateType'],
733
622
  options?: {
734
623
  authMode?: AuthMode;
735
624
  authToken?: string;
@@ -738,7 +627,7 @@ type ModelTypesSSRRequest<
738
627
  ) => SingularReturnValue<Model>;
739
628
  delete: (
740
629
  contextSpec: any,
741
- identifier: ModelIdentifier<ModelMeta>,
630
+ identifier: Model['deleteType'],
742
631
  options?: {
743
632
  authMode?: AuthMode;
744
633
  authToken?: string;
@@ -747,7 +636,7 @@ type ModelTypesSSRRequest<
747
636
  ) => SingularReturnValue<Model>;
748
637
  get<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(
749
638
  contextSpec: any,
750
- identifier: ModelIdentifier<ModelMeta>,
639
+ identifier: Model['identifier'],
751
640
  options?: {
752
641
  selectionSet?: SelectionSet;
753
642
  authMode?: AuthMode;
@@ -757,7 +646,7 @@ type ModelTypesSSRRequest<
757
646
  ): SingularReturnValue<Prettify<ReturnValue<Model, FlatModel, SelectionSet>>>;
758
647
  list<SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[]>(
759
648
  contextSpec: any,
760
- options?: ListPkOptions<ModelMeta, Enums> & {
649
+ options?: ListCpkOptions<Model> & {
761
650
  filter?: ModelFilter<Model>;
762
651
  sortDirection?: ModelSortDirection;
763
652
  limit?: number;
@@ -773,63 +662,36 @@ type ModelTypesSSRRequest<
773
662
  type ContextType = 'CLIENT' | 'COOKIES' | 'REQUEST';
774
663
 
775
664
  export type ModelTypes<
776
- Schema extends Record<any, any>,
665
+ T extends Record<any, any>,
777
666
  Context extends ContextType = 'CLIENT',
778
- ModelMeta extends Record<any, any> = ExtractModelMeta<Schema>,
667
+ Schema extends ClientSchemaByEntityType<T> = ClientSchemaByEntityType<T>,
779
668
  > = {
780
- [ModelName in Exclude<
781
- keyof Schema,
782
- keyof CustomOperations<
783
- Schema,
784
- 'Mutation' | 'Query' | 'Subscription',
785
- Context,
786
- ModelMeta
787
- >
788
- >]: ModelName extends string
789
- ? Schema[ModelName] extends Record<string, unknown>
790
- ? Context extends 'CLIENT'
791
- ? ModelTypesClient<
792
- ModelName,
793
- Schema[ModelName]['type'],
794
- ModelMeta[ModelName],
795
- ModelMeta['enums']
796
- >
797
- : Context extends 'COOKIES'
798
- ? ModelTypesSSRCookies<
799
- ModelName,
800
- Schema[ModelName]['type'],
801
- ModelMeta[ModelName],
802
- ModelMeta['enums']
803
- >
804
- : Context extends 'REQUEST'
805
- ? ModelTypesSSRRequest<
806
- ModelName,
807
- Schema[ModelName]['type'],
808
- ModelMeta[ModelName],
809
- ModelMeta['enums']
810
- >
811
- : never
812
- : never
813
- : never;
669
+ [ModelName in keyof Schema['models']]: Context extends 'CLIENT'
670
+ ? ModelTypesClient<Schema['models'][ModelName]>
671
+ : Context extends 'COOKIES'
672
+ ? ModelTypesSSRCookies<Schema['models'][ModelName]>
673
+ : Context extends 'REQUEST'
674
+ ? ModelTypesSSRRequest<Schema['models'][ModelName]>
675
+ : never;
814
676
  };
815
677
 
816
678
  export type CustomQueries<
817
- Schema extends Record<any, any>,
679
+ T extends Record<any, any>,
818
680
  Context extends ContextType = 'CLIENT',
819
- ModelMeta extends Record<any, any> = ExtractModelMeta<Schema>,
820
- > = CustomOperations<Schema, 'Query', Context, ModelMeta>;
681
+ Schema extends ClientSchemaByEntityType<T> = ClientSchemaByEntityType<T>,
682
+ > = CustomOperations<Schema['queries'], Context>;
821
683
 
822
684
  export type CustomMutations<
823
- Schema extends Record<any, any>,
685
+ T extends Record<any, any>,
824
686
  Context extends ContextType = 'CLIENT',
825
- ModelMeta extends Record<any, any> = ExtractModelMeta<Schema>,
826
- > = CustomOperations<Schema, 'Mutation', Context, ModelMeta>;
687
+ Schema extends ClientSchemaByEntityType<T> = ClientSchemaByEntityType<T>,
688
+ > = CustomOperations<Schema['mutations'], Context>;
827
689
 
828
690
  export type CustomSubscriptions<
829
- Schema extends Record<any, any>,
691
+ T extends Record<any, any>,
830
692
  Context extends ContextType = 'CLIENT',
831
- ModelMeta extends Record<any, any> = ExtractModelMeta<Schema>,
832
- > = CustomOperations<Schema, 'Subscription', Context, ModelMeta>;
693
+ Schema extends ClientSchemaByEntityType<T> = ClientSchemaByEntityType<T>,
694
+ > = CustomOperations<Schema['subscriptions'], Context>;
833
695
 
834
696
  type CustomOperationMethodOptions = {
835
697
  // selectionSet?: SelectionSet;
@@ -848,39 +710,26 @@ type CustomOperationFnParams<Args extends Record<string, unknown> | never> = [
848
710
  : [Args, CustomOperationMethodOptions?];
849
711
 
850
712
  export type CustomOperations<
851
- Schema extends Record<any, any>,
852
- OperationType extends 'Query' | 'Mutation' | 'Subscription',
713
+ OperationDefs extends ClientSchemaByEntityTypeBaseShape[
714
+ | 'queries'
715
+ | 'mutations'
716
+ | 'subscriptions'],
853
717
  Context extends ContextType = 'CLIENT',
854
- ModelMeta extends Record<any, any> = ExtractModelMeta<Schema>,
855
718
  > = {
856
- [OpName in keyof ModelMeta['customOperations'] as ModelMeta['customOperations'][OpName]['typeName'] extends OperationType
857
- ? OpName
858
- : never]: {
719
+ [OpName in keyof OperationDefs]: {
859
720
  CLIENT: (
860
- ...params: CustomOperationFnParams<
861
- ModelMeta['customOperations'][OpName]['arguments']
862
- >
721
+ ...params: CustomOperationFnParams<OperationDefs[OpName]['args']>
863
722
  ) => // we only generate subscriptions on the clientside; so this isn't applied to COOKIES | REQUEST
864
- ModelMeta['customOperations'][OpName]['typeName'] extends 'Subscription'
865
- ? ObservedReturnValue<ModelMeta['customOperations'][OpName]['returnType']>
866
- : SingularReturnValue<
867
- ModelMeta['customOperations'][OpName]['returnType']
868
- >;
723
+ OperationDefs[OpName]['operationType'] extends 'Subscription'
724
+ ? ObservedReturnValue<OperationDefs[OpName]['type']>
725
+ : SingularReturnValue<OperationDefs[OpName]['type']>;
869
726
  COOKIES: (
870
- ...params: CustomOperationFnParams<
871
- ModelMeta['customOperations'][OpName]['arguments']
872
- >
873
- ) => SingularReturnValue<
874
- ModelMeta['customOperations'][OpName]['returnType']
875
- >;
727
+ ...params: CustomOperationFnParams<OperationDefs[OpName]['args']>
728
+ ) => SingularReturnValue<OperationDefs[OpName]['type']>;
876
729
  REQUEST: (
877
730
  contextSpec: any,
878
- ...params: CustomOperationFnParams<
879
- ModelMeta['customOperations'][OpName]['arguments']
880
- >
881
- ) => SingularReturnValue<
882
- ModelMeta['customOperations'][OpName]['returnType']
883
- >;
731
+ ...params: CustomOperationFnParams<OperationDefs[OpName]['args']>
732
+ ) => SingularReturnValue<OperationDefs[OpName]['type']>;
884
733
  }[Context];
885
734
  };
886
735
 
@@ -901,15 +750,19 @@ export type CustomOperations<
901
750
  * }
902
751
  * }
903
752
  */
904
- export type EnumTypes<
905
- Schema extends Record<any, any>,
906
- ModelMeta extends Record<any, any> = ExtractModelMeta<Schema>,
907
- > = {
908
- [EnumName in keyof ModelMeta['enums']]: {
909
- values: () => Array<ModelMeta['enums'][EnumName]>;
753
+ export type EnumTypes<T extends Record<any, any>> = {
754
+ [EnumName in keyof AllEnumTypesRecursively<T>]: {
755
+ values: () => Array<AllEnumTypesRecursively<T>[EnumName]['type']>;
910
756
  };
911
757
  };
912
758
 
759
+ type AllEnumTypesRecursively<T extends Record<any, any>> =
760
+ ClientSchemaByEntityType<T>['enums'] &
761
+ Select<
762
+ ExtractNestedTypes<ClientSchemaByEntityType<T>>,
763
+ { __entityType: 'enum' }
764
+ >;
765
+
913
766
  /**
914
767
  * Request options that are passed to custom header functions.
915
768
  * `method` and `headers` are not included in custom header functions passed to
@@ -930,135 +783,24 @@ export type CustomHeaders =
930
783
  | Record<string, string>
931
784
  | ((requestOptions?: RequestOptions) => Promise<Record<string, string>>);
932
785
 
933
- /**
934
- * PrimaryIndex field types and query methods
935
- */
936
- export interface PrimaryIndexIrShape {
937
- pk: { [key: string]: string | number };
938
- sk: { [key: string]: string | number } | never;
939
- compositeSk: never | string;
940
- }
941
-
942
- /**
943
- * SecondaryIndex field types and query methods
944
- */
945
- export interface SecondaryIndexIrShape extends PrimaryIndexIrShape {
946
- defaultQueryFieldSuffix: string;
947
- queryField: string;
948
- }
949
-
950
- export type IndexQueryMethodsFromIR<
951
- SecondaryIdxTuple extends SecondaryIndexIrShape[],
952
- ModelName extends string,
953
- Model extends Record<string, unknown>,
954
- Enums extends Record<string, string>,
955
- Res = unknown, // defaulting `unknown` because it gets absorbed in an intersection, e.g. `{a: 1} & unknown` => `{a: 1}`
956
- > = SecondaryIdxTuple extends [
957
- infer A extends SecondaryIndexIrShape,
958
- ...infer B extends SecondaryIndexIrShape[],
959
- ]
960
- ? IndexQueryMethodsFromIR<
961
- B,
962
- ModelName,
963
- Model,
964
- Enums,
965
- IndexQueryMethodSignature<A, ModelName, Model, Enums> & Res
966
- >
967
- : Res;
968
-
969
- export type ListPkOptions<
970
- ModelMeta extends ModelMetaShape,
971
- Enums extends Record<string, string>,
972
- > = ModelMeta['identifier']['sk'] extends never
973
- ? unknown
974
- : Prettify<
975
- Partial<IndexQueryInput<ModelMeta['identifier'], Enums>> & {
976
- sortDirection?: ModelSortDirection;
977
- }
978
- >;
979
-
980
- /**
981
- * Accepts a PrimaryIndexIr or SecondaryIndexIr and returns resolved parameters
982
- */
983
- export type IndexQueryInput<
984
- Idx extends PrimaryIndexIrShape,
985
- Enums extends Record<string, string>,
986
- > = {
987
- [PKField in keyof Idx['pk']]: Idx['pk'][PKField] extends `${deferredRefResolvingPrefix}${infer R}`
988
- ? Enums[R]
989
- : Idx['pk'][PKField];
990
- } & (Idx['compositeSk'] extends never
991
- ? {
992
- [SKField in keyof Idx['sk']]+?: number extends Idx['sk'][SKField]
993
- ? NumericFilter
994
- : Idx['sk'][SKField] extends `${deferredRefResolvingPrefix}${infer R}`
995
- ? StringFilter<Enums[R]>
996
- : StringFilter<Idx['sk'][SKField] & string>;
997
- }
998
- : {
999
- [CompositeSk in Idx['compositeSk']]+?: ModelPrimaryCompositeKeyInput<{
1000
- [SKField in keyof Idx['sk']]: Idx['sk'][SKField] extends `${deferredRefResolvingPrefix}${infer _R}`
1001
- ? string
1002
- : Idx['sk'][SKField];
1003
- }>;
1004
- });
1005
-
1006
- type IndexQueryMethodSignature<
1007
- Idx extends SecondaryIndexIrShape,
1008
- ModelName extends string,
1009
- Model extends Record<string, unknown>,
1010
- Enums extends Record<string, string>,
1011
- > = Record<
1012
- IsEmptyStringOrNever<Idx['queryField']> extends false
1013
- ? Idx['queryField']
1014
- : `list${ModelName}By${Idx['defaultQueryFieldSuffix']}`,
1015
- <
1016
- FlatModel extends Record<string, unknown> = ResolvedModel<Model>,
1017
- SelectionSet extends ReadonlyArray<ModelPath<FlatModel>> = never[],
1018
- >(
1019
- input: IndexQueryInput<Idx, Enums>,
1020
- options?: {
1021
- filter?: ModelFilter<Model>;
1022
- sortDirection?: ModelSortDirection;
1023
- limit?: number;
1024
- nextToken?: string | null;
1025
- selectionSet?: SelectionSet;
1026
- authMode?: AuthMode;
1027
- authToken?: string;
1028
- headers?: CustomHeaders;
1029
- },
1030
- ) => ListReturnValue<Prettify<ReturnValue<Model, FlatModel, SelectionSet>>>
1031
- >;
1032
-
1033
- type FilteredKeys<T> = {
1034
- [P in keyof T]: T[P] extends never ? never : P;
1035
- }[keyof T];
1036
-
1037
- type ExcludeNeverFields<O> = {
1038
- [K in FilteredKeys<O>]: O[K];
786
+ export type ClientExtensions<T extends Record<any, any> = never> = {
787
+ models: ModelTypes<T, 'CLIENT'>;
788
+ enums: EnumTypes<T>;
789
+ queries: CustomQueries<T, 'CLIENT'>;
790
+ mutations: CustomMutations<T, 'CLIENT'>;
791
+ subscriptions: CustomSubscriptions<T, 'CLIENT'>;
1039
792
  };
1040
793
 
1041
- export type ClientExtensions<T extends Record<any, any> = never> =
1042
- ExcludeNeverFields<{
1043
- models: ModelTypes<T, 'CLIENT'>;
1044
- enums: EnumTypes<T>;
1045
- queries: CustomQueries<T, 'CLIENT'>;
1046
- mutations: CustomMutations<T, 'CLIENT'>;
1047
- subscriptions: CustomSubscriptions<T, 'CLIENT'>;
1048
- }>;
1049
-
1050
- export type ClientExtensionsSSRRequest<T extends Record<any, any> = never> =
1051
- ExcludeNeverFields<{
1052
- models: ModelTypes<T, 'REQUEST'>;
1053
- enums: EnumTypes<T>;
1054
- queries: CustomQueries<T, 'REQUEST'>;
1055
- mutations: CustomMutations<T, 'REQUEST'>;
1056
- }>;
794
+ export type ClientExtensionsSSRRequest<T extends Record<any, any> = never> = {
795
+ models: ModelTypes<T, 'REQUEST'>;
796
+ enums: EnumTypes<T>;
797
+ queries: CustomQueries<T, 'REQUEST'>;
798
+ mutations: CustomMutations<T, 'REQUEST'>;
799
+ };
1057
800
 
1058
- export type ClientExtensionsSSRCookies<T extends Record<any, any> = never> =
1059
- ExcludeNeverFields<{
1060
- models: ModelTypes<T, 'COOKIES'>;
1061
- enums: EnumTypes<T>;
1062
- queries: CustomQueries<T, 'COOKIES'>;
1063
- mutations: CustomMutations<T, 'COOKIES'>;
1064
- }>;
801
+ export type ClientExtensionsSSRCookies<T extends Record<any, any> = never> = {
802
+ models: ModelTypes<T, 'COOKIES'>;
803
+ enums: EnumTypes<T>;
804
+ queries: CustomQueries<T, 'COOKIES'>;
805
+ mutations: CustomMutations<T, 'COOKIES'>;
806
+ };