json-rest-api 2.1.0 → 2.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 (29) hide show
  1. package/docs/API.md +80 -0
  2. package/docs/GUIDE/17-row-policies.md +1 -0
  3. package/docs/GUIDE/21-schema-and-migrations.md +99 -2
  4. package/docs/GUIDE/30-backend-capabilities.md +3 -1
  5. package/docs/GUIDE/33-migrating-to-v2.md +20 -0
  6. package/package.json +1 -1
  7. package/plugins/core/lib/anyapi/anyapi-registry.js +97 -42
  8. package/plugins/core/lib/anyapi/schema-utils.js +168 -53
  9. package/plugins/core/lib/anyapi/stored-definition.js +3 -0
  10. package/plugins/core/lib/dbIntrospection.js +28 -0
  11. package/plugins/core/lib/querying/aggregate-query.js +170 -0
  12. package/plugins/core/lib/querying/knex-query-helpers.js +14 -4
  13. package/plugins/core/lib/querying-writing/compile-schemas.js +17 -0
  14. package/plugins/core/lib/querying-writing/database-value-normalizers.js +16 -0
  15. package/plugins/core/lib/querying-writing/default-data-helpers.js +4 -0
  16. package/plugins/core/lib/querying-writing/field-types.js +43 -0
  17. package/plugins/core/lib/querying-writing/request-contracts.js +1 -1
  18. package/plugins/core/lib/storage/canonical-data-helpers.js +29 -0
  19. package/plugins/core/lib/storage/canonical-storage-mapping.js +11 -0
  20. package/plugins/core/lib/storage/ordinary-data-helpers.js +25 -0
  21. package/plugins/core/lib/storage/storage-types.d.ts +23 -0
  22. package/plugins/core/rest-api-anyapi-knex-plugin.js +140 -31
  23. package/plugins/core/rest-api-plugin-methods/aggregate.js +41 -0
  24. package/plugins/core/rest-api-plugin-methods/common.js +16 -1
  25. package/plugins/core/rest-api-plugin.js +2 -0
  26. package/types/anyapi.d.ts +13 -2
  27. package/types/plugin-options.d.ts +2 -1
  28. package/types/resource-methods.d.ts +19 -0
  29. package/types/resource-schema.d.ts +5 -3
@@ -1,7 +1,7 @@
1
1
  import type { StorageFieldDefinition, StorageQuery } from '../plugins/core/lib/storage/storage-types.js'
2
2
  import type { FileStorage } from './file-storage.js'
3
3
 
4
- export type ResourceFieldType = 'string' | 'number' | 'integer' | 'boolean' | 'id' |
4
+ export type ResourceFieldType = 'string' | 'email' | 'uuid' | 'number' | 'integer' | 'boolean' | 'id' |
5
5
  'date' | 'time' | 'dateTime' | 'epochSeconds' | 'epochMilliseconds' |
6
6
  'array' | 'object' | 'file' | 'blob' | 'serialize' | 'none'
7
7
 
@@ -46,6 +46,8 @@ export interface ResourceFieldOptions {
46
46
  normallyHidden?: boolean
47
47
  virtual?: boolean
48
48
  computed?: boolean
49
+ // Readable and filterable, but rejects new values.
50
+ retired?: boolean
49
51
  include?: ResourceRelationshipOptions['include']
50
52
  search?: boolean | ResourceSearchOptions | Record<string, ResourceSearchOptions>
51
53
  dependencies?: readonly string[]
@@ -113,7 +115,7 @@ type ObjectValue<Field, Mode extends Direction> =
113
115
  : Field extends { values: infer Values } ? Record<string, NestedValue<Values, Mode>> : Record<string, unknown>
114
116
 
115
117
  type BaseValue<Field, Mode extends Direction> =
116
- Field extends { type: 'string' | 'file' | 'date' | 'time' | 'dateTime' } ? string
118
+ Field extends { type: 'string' | 'email' | 'uuid' | 'file' | 'date' | 'time' | 'dateTime' } ? string
117
119
  : Field extends { type: 'number'; precision: number; scale: number } ? Mode extends 'output' ? string | number : number
118
120
  : Field extends { type: 'number' | 'integer' | 'epochSeconds' | 'epochMilliseconds' } ? number
119
121
  : Field extends { type: 'boolean' } ? boolean
@@ -147,7 +149,7 @@ type StoredNull<Field> = Field extends { required: true } | { nullable: false }
147
149
  // Attribute helpers exclude the conventional ID and relationship backing fields.
148
150
  // Hooks/defaults may supply required values, so caller input stays optional.
149
151
  export type InferInput<Schema extends object> = {
150
- -readonly [Key in keyof Schema as Schema[Key] extends { computed: true } ? never : AttributeKey<Schema, Key>]?: FieldValue<Schema[Key], 'input'>
152
+ -readonly [Key in keyof Schema as Schema[Key] extends { computed: true } | { retired: true } ? never : AttributeKey<Schema, Key>]?: FieldValue<Schema[Key], 'input'>
151
153
  }
152
154
 
153
155
  // Resource result types add optionality for sparse fields and permissions.