utilium 2.3.3 → 2.3.5

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.
@@ -70,6 +70,8 @@ interface SetOptions extends Options {
70
70
  offset?: number;
71
71
  /** If a cache for the resource doesn't exist, this will be used as the full size */
72
72
  size?: number;
73
+ /** The method to use for the request */
74
+ method?: 'POST' | 'PUT';
73
75
  }
74
76
  /**
75
77
  * Make a POST request to set (or create) data on the server and update the cache.
package/dist/requests.js CHANGED
@@ -116,9 +116,26 @@ export async function set(url, data, options, init = {}) {
116
116
  new cache.Resource(url, options.size ?? data.byteLength, options, resourcesCache);
117
117
  }
118
118
  const resource = resourcesCache.get(url);
119
- const { offset = 0 } = options;
120
- if (!options.cacheOnly)
121
- await _fetch(new Request(url, init), { method: 'POST' }, true);
119
+ const { offset = 0, method = 'POST' } = options;
120
+ // Skip the server request if we are only updating the cache
121
+ if (!options.cacheOnly) {
122
+ const headers = new Headers(init.headers || {});
123
+ if (!headers.get('Content-Type')) {
124
+ headers.set('Content-Type', 'application/octet-stream');
125
+ }
126
+ if (!headers.get('Content-Range') && (offset !== 0 || data.byteLength !== resource.size)) {
127
+ const start = offset;
128
+ const end = offset + data.byteLength - 1;
129
+ const total = Math.max(resource.size, end + 1);
130
+ headers.set('Content-Range', `bytes ${start}-${end}/${total}`);
131
+ }
132
+ await _fetch(new Request(url, {
133
+ ...init,
134
+ method,
135
+ headers,
136
+ body: data,
137
+ }), {}, true);
138
+ }
122
139
  resource.add(data, offset);
123
140
  }
124
141
  /**
package/dist/types.d.ts CHANGED
@@ -166,6 +166,7 @@ export type OptionalTuple<T extends unknown[]> = T extends [infer Head, ...infer
166
166
  */
167
167
  export type MapKeys<T> = T extends Map<infer K, any> ? K : never;
168
168
  export type ClassLike<Instance = any> = abstract new (...args: any[]) => Instance;
169
+ export type InstancesFor<T extends ClassLike[]> = T extends [] ? [] : T extends [infer C extends ClassLike, ...infer Rest extends ClassLike[]] ? [InstanceType<C>, ...InstancesFor<Rest>] : never;
169
170
  export type Concrete<T extends ClassLike> = Pick<T, keyof T> & (new (...args: any[]) => InstanceType<T>);
170
171
  /**
171
172
  * Converts a union to an intersection
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utilium",
3
- "version": "2.3.3",
3
+ "version": "2.3.5",
4
4
  "description": "Typescript utilities",
5
5
  "funding": {
6
6
  "type": "individual",