@trypattern/sdk 0.1.30 → 0.1.32

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.
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import type { PickedFile } from './files.ts';
2
3
  import type { SameOnTheWire } from './wire.ts';
3
4
  type Shape = z.ZodRawShape;
4
5
  type NoShape = Record<never, never>;
@@ -6,11 +7,16 @@ type ParamNames<Path extends string> = Path extends `${string}:${infer Param}/${
6
7
  export type ParamsOf<Path extends string> = {
7
8
  readonly [Name in ParamNames<Path>]: string;
8
9
  };
9
- export type ServiceCall<Path extends string = string, S extends Shape = Shape, Reply extends z.ZodType = z.ZodType> = {
10
+ export type ServiceCall<Path extends string = string, S extends Shape = Shape, Reply extends z.ZodType = z.ZodType, Upload extends boolean = boolean> = {
10
11
  readonly method: 'get' | 'post';
11
12
  readonly path: Path;
12
13
  readonly input: z.ZodObject<S>;
13
14
  readonly reply: Reply;
15
+ readonly isUpload: Upload;
16
+ };
17
+ export type UploadOptions = {
18
+ readonly onProgress?: (sent: number, total: number) => void;
19
+ readonly signal?: AbortSignal;
14
20
  };
15
21
  type StaticTypeError<Message extends string> = Message;
16
22
  type NotText = StaticTypeError<'A get call sends its input in the address, where everything is text: use z.string() or z.enum() here, or make it a post call'>;
@@ -26,12 +32,30 @@ type CallOptions<Path extends string, S extends Shape, Reply extends z.ZodType>
26
32
  input?: SameOnTheWire<S>;
27
33
  reply: Reply;
28
34
  };
29
- export declare function call<Path extends string, Reply extends z.ZodType, S extends Shape = NoShape>(options: CallOptions<Path, S, Reply>): NoInfer<ServiceCall<Path, S, Reply>>;
35
+ type UploadCallOptions<Path extends string, S extends Shape, Reply extends z.ZodType> = {
36
+ upload: Path;
37
+ input?: TextOnly<S> & SameOnTheWire<S>;
38
+ reply: Reply;
39
+ };
40
+ export declare function call<Path extends string, Reply extends z.ZodType, S extends Shape = NoShape>(options: UploadCallOptions<Path, S, Reply>): NoInfer<ServiceCall<Path, S, Reply, true>>;
41
+ export declare function call<Path extends string, Reply extends z.ZodType, S extends Shape = NoShape>(options: CallOptions<Path, S, Reply>): NoInfer<ServiceCall<Path, S, Reply, false>>;
30
42
  export type Services = Readonly<Record<string, Readonly<Record<string, ServiceCall>>>>;
31
43
  export declare function defineServices<const Group extends Services>(services: Group): Group;
32
- export type CallInput<Call> = Call extends ServiceCall<infer Path, infer S, z.ZodType> ? ParamsOf<Path> & (keyof S extends never ? NoShape : z.output<z.ZodObject<S>>) : never;
44
+ type FieldsOf<Call> = Call extends ServiceCall<infer Path, infer S, z.ZodType> ? ParamsOf<Path> & (keyof S extends never ? NoShape : z.output<z.ZodObject<S>>) : never;
45
+ export type CallInput<Call> = FieldsOf<Call> & (Call extends {
46
+ readonly isUpload: true;
47
+ } ? {
48
+ file: PickedFile;
49
+ } : NoShape);
50
+ export type HandlerInput<Call> = FieldsOf<Call> & (Call extends {
51
+ readonly isUpload: true;
52
+ } ? {
53
+ file: File;
54
+ } : NoShape);
33
55
  export type CallReply<Call> = Call extends ServiceCall<string, Shape, infer Reply> ? z.output<Reply> : never;
34
- type ClientCall<Call> = keyof CallInput<Call> extends never ? (input?: CallInput<Call>) => Promise<CallReply<Call>> : (input: CallInput<Call>) => Promise<CallReply<Call>>;
56
+ type ClientCall<Call> = Call extends {
57
+ readonly isUpload: true;
58
+ } ? (input: CallInput<Call>, options?: UploadOptions) => Promise<CallReply<Call>> : keyof CallInput<Call> extends never ? (input?: CallInput<Call>) => Promise<CallReply<Call>> : (input: CallInput<Call>) => Promise<CallReply<Call>>;
35
59
  export type ServiceClient<Group extends Services> = {
36
60
  readonly [Name in keyof Group]: {
37
61
  readonly [Call in keyof Group[Name]]: ClientCall<Group[Name][Call]>;
package/dist/services.js CHANGED
@@ -1,12 +1,16 @@
1
1
  import { z } from 'zod';
2
2
  export function call(options) {
3
- const method = 'get' in options ? 'get' : 'post';
4
- const path = 'get' in options ? options.get : options.post;
3
+ const path = 'get' in options
4
+ ? options.get
5
+ : 'post' in options
6
+ ? options.post
7
+ : options.upload;
5
8
  return {
6
- method,
9
+ method: 'get' in options ? 'get' : 'post',
7
10
  path,
8
11
  input: z.object((options.input ?? {})),
9
- reply: options.reply
12
+ reply: options.reply,
13
+ isUpload: 'upload' in options
10
14
  };
11
15
  }
12
16
  export function defineServices(services) {
@@ -1,4 +1,7 @@
1
1
  import * as stylex from '@stylexjs/stylex';
2
+ export declare const galleryMarker: Readonly<{
3
+ readonly marker: stylex.StyleXClassNameFor<"marker", symbol>;
4
+ }>;
2
5
  export declare const breakpoints: {
3
6
  compact: string;
4
7
  canHover: string;
@@ -148,6 +151,7 @@ export declare const widths: stylex.VarGroup<Readonly<{
148
151
  toast: string;
149
152
  }>, symbol>;
150
153
  export declare const layers: {
154
+ header: string;
151
155
  scrim: string;
152
156
  sidebar: string;
153
157
  menu: string;
@@ -1,4 +1,5 @@
1
1
  import * as stylex from '@stylexjs/stylex';
2
+ export const galleryMarker = stylex.defineMarker();
2
3
  export const breakpoints = stylex.defineConsts({
3
4
  compact: '@media (max-width: 767px)',
4
5
  canHover: '@media (hover: hover)',
@@ -148,6 +149,7 @@ export const widths = stylex.defineVars({
148
149
  toast: '356px'
149
150
  });
150
151
  export const layers = stylex.defineConsts({
152
+ header: '10',
151
153
  scrim: '15',
152
154
  sidebar: '20',
153
155
  menu: '20',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trypattern/sdk",
3
- "version": "0.1.30",
3
+ "version": "0.1.32",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",