@archtx/procedures 4.0.1 → 5.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@archtx/procedures",
3
- "version": "4.0.1",
3
+ "version": "5.0.0",
4
4
  "description": "Procedure generator for @archtx",
5
5
  "main": "dist/exports.js",
6
6
  "types": "dist/exports.d.ts",
@@ -29,11 +29,11 @@
29
29
  "ajv-formats": "^3.0.1"
30
30
  },
31
31
  "peerDependencies": {
32
- "@sinclair/typebox": "^0.34.28",
32
+ "typebox": "^1.0.30",
33
33
  "suretype": "^3.3.1"
34
34
  },
35
35
  "devDependencies": {
36
- "@sinclair/typebox": "^0.34.28",
36
+ "typebox": "^1.0.30",
37
37
  "@types/jest": "^29.5.11",
38
38
  "@typescript-eslint/eslint-plugin": "^5.48.1",
39
39
  "@typescript-eslint/parser": "^5.48.1",
package/src/index.ts CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  } from './errors.js'
6
6
  import { ProcedureCodes } from './procedure-codes.js'
7
7
  import { computeSchema } from './schema/compute-schema.js'
8
- import { TJSONSchema, TSchemaLib } from './schema/types.js'
8
+ import { Prettify, TJSONSchema, TSchemaLib } from './schema/types.js'
9
9
 
10
10
  export type TNoContextProvided = unknown
11
11
 
@@ -47,7 +47,7 @@ export function Procedures<TContext = TNoContextProvided>(
47
47
  {
48
48
  name: string
49
49
  config: TProcedureRegistration['config']
50
- handler: (ctx: TContext, args: any) => Promise<any>
50
+ handler: (ctx: Prettify<TContext>, args: any) => Promise<any>
51
51
  }
52
52
  > = new Map()
53
53
 
@@ -56,21 +56,21 @@ export function Procedures<TContext = TNoContextProvided>(
56
56
  config: {
57
57
  description?: string
58
58
  hook?: (
59
- ctx: TContext & TLocalContext,
59
+ ctx: Prettify<TContext & TLocalContext>,
60
60
  args: TSchemaLib<TArgs>,
61
- ) => Promise<TLocalHook>
61
+ ) => Promise<Prettify<TLocalHook>>
62
62
  schema?: {
63
63
  args?: TArgs
64
64
  data?: TData
65
65
  }
66
66
  },
67
67
  handler: (
68
- ctx: TContext & TLocalContext & TLocalHook,
68
+ ctx: Prettify<TContext & TLocalContext & TLocalHook>,
69
69
  args: TSchemaLib<TArgs>,
70
70
  ) => Promise<TSchemaLib<TData>>,
71
71
  ): {
72
72
  [K in TName | `${TName}_Info`]: K extends TName
73
- ? (ctx: TContext, args: TSchemaLib<TArgs>) => Promise<TSchemaLib<TData>>
73
+ ? (ctx: Prettify<TContext>, args: TSchemaLib<TArgs>) => Promise<TSchemaLib<TData>>
74
74
  : {
75
75
  description?: string
76
76
  schema: {
@@ -92,7 +92,7 @@ export function Procedures<TContext = TNoContextProvided>(
92
92
  },
93
93
  },
94
94
 
95
- handler: async (ctx: TContext, args: TSchemaLib<TArgs>) => {
95
+ handler: async (ctx: Prettify<TContext>, args: TSchemaLib<TArgs>) => {
96
96
  try {
97
97
  if (validations?.args) {
98
98
  const { errors } = validations.args(args)
@@ -143,7 +143,7 @@ export function Procedures<TContext = TNoContextProvided>(
143
143
  ...ctx,
144
144
  ...localCtx,
145
145
  ...computedLocalHook,
146
- } as TContext & TLocalContext & TLocalHook,
146
+ } as Prettify<TContext & TLocalContext & TLocalHook>,
147
147
  args,
148
148
  )
149
149
  } catch (error: any) {
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect } from 'vitest'
2
- import { Type } from '@sinclair/typebox'
2
+ import { Type } from 'typebox'
3
3
  import { v } from 'suretype'
4
4
  import { computeSchema } from './compute-schema.js'
5
5
  import { ProcedureRegistrationError } from '../errors.js'
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, test } from 'vitest'
2
- import { Type } from '@sinclair/typebox'
2
+ import { Type } from 'typebox'
3
3
  import { v } from 'suretype'
4
4
  import { extractJsonSchema } from './extract-json-schema.js'
5
5
 
@@ -1,7 +1,7 @@
1
1
  import { describe, expect, test } from 'vitest'
2
2
  import { extractSingleJsonSchema, v } from 'suretype'
3
3
  import { schemaParser } from './parser.js'
4
- import { Type } from '@sinclair/typebox'
4
+ import { Type } from 'typebox'
5
5
 
6
6
  describe('schemaParser', () => {
7
7
  test('it parses args to json-schema', async () => {
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, test } from 'vitest'
2
2
  import { isSuretypeSchema, isTypeboxSchema } from './resolve-schema-lib.js'
3
- import { Type } from '@sinclair/typebox'
3
+ import { Type } from 'typebox'
4
4
  import { v } from 'suretype'
5
5
 
6
6
  describe('lib schema resolvers', () => {
@@ -1,23 +1,29 @@
1
- import { Static } from '@sinclair/typebox'
2
1
  import { CoreValidator } from 'suretype'
2
+ import { Type } from 'typebox'
3
3
 
4
- export type IsTypeboxSchema<TSchema> =
5
- TSchema extends {static: unknown, params: unknown} ? true
6
- : false;
7
-
8
- export function isTypeboxSchema(
9
- schema: any,
10
- ): schema is Static<any> {
11
- return typeof schema === 'object' && Symbol.for('TypeBox.Kind') in schema;
4
+ export type IsTypeboxSchema<TSchema> = TSchema extends {
5
+ static: unknown
6
+ params: unknown
12
7
  }
8
+ ? true
9
+ : false
13
10
 
14
- export type IsSuretypeSchema<TSchema> =
15
- TSchema extends {required: () => object, nullable?: never} ? true
16
- : false;
11
+ export function isTypeboxSchema(schema: any): schema is Type.TSchema {
12
+ return (
13
+ // typebox v1
14
+ (typeof schema === 'object' && '~kind' in schema) ||
15
+ // @sinclair/typebox v0.3x
16
+ (typeof schema === 'object' && Symbol.for('TypeBox.Kind') in schema)
17
+ )
18
+ }
17
19
 
18
- export function isSuretypeSchema(
19
- schema: any,
20
- ): schema is CoreValidator<any> {
21
- return typeof schema === 'object' && 'getJsonSchemaObject' in schema;
20
+ export type IsSuretypeSchema<TSchema> = TSchema extends {
21
+ required: () => object
22
+ nullable?: never
22
23
  }
24
+ ? true
25
+ : false
23
26
 
27
+ export function isSuretypeSchema(schema: any): schema is CoreValidator<any> {
28
+ return typeof schema === 'object' && 'getJsonSchemaObject' in schema
29
+ }
@@ -1,5 +1,6 @@
1
+ /* eslint-disable @typescript-eslint/ban-types */
1
2
  import { CoreValidator, TypeOf } from 'suretype'
2
- import { Static, TSchema } from '@sinclair/typebox'
3
+ import { Static, TSchema } from 'typebox'
3
4
 
4
5
  // Determine if the generic "SchemaLibType" is Suretype's CoreValidator or Typebox's TSchema
5
6
  export type TSchemaLib<SchemaLibType> =
@@ -10,3 +11,7 @@ export type TSchemaLib<SchemaLibType> =
10
11
  : unknown
11
12
 
12
13
  export type TJSONSchema = Record<string, any>
14
+
15
+ export type Prettify<TObject> = {
16
+ [Key in keyof TObject]: TObject[Key]
17
+ } & {}