@slates/provider 1.0.0-rc.19 → 1.0.0-rc.20
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/dist/index.cjs +29 -2
- package/dist/index.module.js +30 -3
- package/package.json +1 -1
- package/src/context/context.ts +10 -3
- package/src/context/hook.test.ts +19 -0
- package/src/context/pQueue.ts +4 -0
- package/src/module/resolveDefaultExport.test.ts +32 -0
- package/src/module/resolveDefaultExport.ts +14 -0
package/dist/index.cjs
CHANGED
|
@@ -2264,7 +2264,28 @@ var config = (schema) => SlateConfig.create(schema);
|
|
|
2264
2264
|
|
|
2265
2265
|
// src/context/context.ts
|
|
2266
2266
|
var import_node_stream = require("stream");
|
|
2267
|
+
|
|
2268
|
+
// src/context/pQueue.ts
|
|
2267
2269
|
var import_p_queue = __toESM(require("p-queue"), 1);
|
|
2270
|
+
|
|
2271
|
+
// src/module/resolveDefaultExport.ts
|
|
2272
|
+
var resolveDefaultExport = (value) => {
|
|
2273
|
+
let current = value;
|
|
2274
|
+
for (let i = 0; i < 4; i++) {
|
|
2275
|
+
if (typeof current === "function") return current;
|
|
2276
|
+
if (current && typeof current === "object" && "default" in current) {
|
|
2277
|
+
current = current.default;
|
|
2278
|
+
continue;
|
|
2279
|
+
}
|
|
2280
|
+
break;
|
|
2281
|
+
}
|
|
2282
|
+
throw new TypeError("Module export is not a constructor");
|
|
2283
|
+
};
|
|
2284
|
+
|
|
2285
|
+
// src/context/pQueue.ts
|
|
2286
|
+
var PQueue = resolveDefaultExport(import_p_queue.default);
|
|
2287
|
+
|
|
2288
|
+
// src/context/context.ts
|
|
2268
2289
|
var isBufferLike = (value) => value instanceof Uint8Array || value instanceof ArrayBuffer;
|
|
2269
2290
|
var toUint8Array = (value) => value instanceof ArrayBuffer ? new Uint8Array(value) : value;
|
|
2270
2291
|
var isReadableStream = (value) => typeof ReadableStream !== "undefined" && value instanceof ReadableStream;
|
|
@@ -2295,7 +2316,13 @@ var SlatePublicContext = class {
|
|
|
2295
2316
|
#attachmentsDisabled = false;
|
|
2296
2317
|
#attachments = [];
|
|
2297
2318
|
#pendingUploads = [];
|
|
2298
|
-
#uploadQueue
|
|
2319
|
+
#uploadQueue;
|
|
2320
|
+
#getUploadQueue() {
|
|
2321
|
+
if (!this.#uploadQueue) {
|
|
2322
|
+
this.#uploadQueue = new PQueue({ concurrency: 10 });
|
|
2323
|
+
}
|
|
2324
|
+
return this.#uploadQueue;
|
|
2325
|
+
}
|
|
2299
2326
|
get specification() {
|
|
2300
2327
|
return this.spec;
|
|
2301
2328
|
}
|
|
@@ -2383,7 +2410,7 @@ var SlatePublicContext = class {
|
|
|
2383
2410
|
return;
|
|
2384
2411
|
}
|
|
2385
2412
|
let live = this.#liveInvocation;
|
|
2386
|
-
let task = this.#
|
|
2413
|
+
let task = this.#getUploadQueue().add(
|
|
2387
2414
|
() => uploadAttachmentDirect({
|
|
2388
2415
|
live,
|
|
2389
2416
|
mimeType: normalized.mimeType,
|
package/dist/index.module.js
CHANGED
|
@@ -2155,7 +2155,28 @@ var config = (schema) => SlateConfig.create(schema);
|
|
|
2155
2155
|
|
|
2156
2156
|
// src/context/context.ts
|
|
2157
2157
|
import { Readable } from "stream";
|
|
2158
|
-
|
|
2158
|
+
|
|
2159
|
+
// src/context/pQueue.ts
|
|
2160
|
+
import PQueueImport from "p-queue";
|
|
2161
|
+
|
|
2162
|
+
// src/module/resolveDefaultExport.ts
|
|
2163
|
+
var resolveDefaultExport = (value) => {
|
|
2164
|
+
let current = value;
|
|
2165
|
+
for (let i = 0; i < 4; i++) {
|
|
2166
|
+
if (typeof current === "function") return current;
|
|
2167
|
+
if (current && typeof current === "object" && "default" in current) {
|
|
2168
|
+
current = current.default;
|
|
2169
|
+
continue;
|
|
2170
|
+
}
|
|
2171
|
+
break;
|
|
2172
|
+
}
|
|
2173
|
+
throw new TypeError("Module export is not a constructor");
|
|
2174
|
+
};
|
|
2175
|
+
|
|
2176
|
+
// src/context/pQueue.ts
|
|
2177
|
+
var PQueue = resolveDefaultExport(PQueueImport);
|
|
2178
|
+
|
|
2179
|
+
// src/context/context.ts
|
|
2159
2180
|
var isBufferLike = (value) => value instanceof Uint8Array || value instanceof ArrayBuffer;
|
|
2160
2181
|
var toUint8Array = (value) => value instanceof ArrayBuffer ? new Uint8Array(value) : value;
|
|
2161
2182
|
var isReadableStream = (value) => typeof ReadableStream !== "undefined" && value instanceof ReadableStream;
|
|
@@ -2186,7 +2207,13 @@ var SlatePublicContext = class {
|
|
|
2186
2207
|
#attachmentsDisabled = false;
|
|
2187
2208
|
#attachments = [];
|
|
2188
2209
|
#pendingUploads = [];
|
|
2189
|
-
#uploadQueue
|
|
2210
|
+
#uploadQueue;
|
|
2211
|
+
#getUploadQueue() {
|
|
2212
|
+
if (!this.#uploadQueue) {
|
|
2213
|
+
this.#uploadQueue = new PQueue({ concurrency: 10 });
|
|
2214
|
+
}
|
|
2215
|
+
return this.#uploadQueue;
|
|
2216
|
+
}
|
|
2190
2217
|
get specification() {
|
|
2191
2218
|
return this.spec;
|
|
2192
2219
|
}
|
|
@@ -2274,7 +2301,7 @@ var SlatePublicContext = class {
|
|
|
2274
2301
|
return;
|
|
2275
2302
|
}
|
|
2276
2303
|
let live = this.#liveInvocation;
|
|
2277
|
-
let task = this.#
|
|
2304
|
+
let task = this.#getUploadQueue().add(
|
|
2278
2305
|
() => uploadAttachmentDirect({
|
|
2279
2306
|
live,
|
|
2280
2307
|
mimeType: normalized.mimeType,
|
package/package.json
CHANGED
package/src/context/context.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Readable } from 'node:stream';
|
|
2
|
-
import PQueue from 'p-queue';
|
|
3
2
|
import {
|
|
4
3
|
createBase64Attachment,
|
|
5
4
|
createUrlAttachment,
|
|
@@ -9,6 +8,7 @@ import { type SlateLiveInvocationInfo, uploadAttachmentDirect } from '../action/
|
|
|
9
8
|
import type { SlateHttpTrace } from '../axios/trace';
|
|
10
9
|
import type { SlateLogger, SlateLogMessageInput } from '../logger';
|
|
11
10
|
import type { SlateSpecification } from '../specification/specification';
|
|
11
|
+
import { PQueue } from './pQueue';
|
|
12
12
|
|
|
13
13
|
export type { SlateLiveInvocationInfo };
|
|
14
14
|
|
|
@@ -83,7 +83,14 @@ export class SlatePublicContext<InputType extends {}> {
|
|
|
83
83
|
#attachmentsDisabled = false;
|
|
84
84
|
#attachments: SlateAttachment[] = [];
|
|
85
85
|
#pendingUploads: Promise<void>[] = [];
|
|
86
|
-
#uploadQueue
|
|
86
|
+
#uploadQueue?: InstanceType<typeof PQueue>;
|
|
87
|
+
|
|
88
|
+
#getUploadQueue() {
|
|
89
|
+
if (!this.#uploadQueue) {
|
|
90
|
+
this.#uploadQueue = new PQueue({ concurrency: 10 });
|
|
91
|
+
}
|
|
92
|
+
return this.#uploadQueue;
|
|
93
|
+
}
|
|
87
94
|
|
|
88
95
|
constructor(
|
|
89
96
|
input: InputType,
|
|
@@ -207,7 +214,7 @@ export class SlatePublicContext<InputType extends {}> {
|
|
|
207
214
|
}
|
|
208
215
|
|
|
209
216
|
let live = this.#liveInvocation;
|
|
210
|
-
let task = this.#
|
|
217
|
+
let task = this.#getUploadQueue()
|
|
211
218
|
.add(() =>
|
|
212
219
|
uploadAttachmentDirect({
|
|
213
220
|
live,
|
package/src/context/hook.test.ts
CHANGED
|
@@ -3,6 +3,25 @@ import { SlateContext } from './context';
|
|
|
3
3
|
import { runWithContext } from './hook';
|
|
4
4
|
|
|
5
5
|
describe('slate context hook', () => {
|
|
6
|
+
it('constructs a context without requiring p-queue at construction time', () => {
|
|
7
|
+
expect(
|
|
8
|
+
() =>
|
|
9
|
+
new SlateContext(
|
|
10
|
+
{},
|
|
11
|
+
{},
|
|
12
|
+
{},
|
|
13
|
+
{} as any,
|
|
14
|
+
{
|
|
15
|
+
debug: () => {},
|
|
16
|
+
error: () => {},
|
|
17
|
+
info: () => {},
|
|
18
|
+
progress: () => {},
|
|
19
|
+
warn: () => {}
|
|
20
|
+
} as any
|
|
21
|
+
)
|
|
22
|
+
).not.toThrow();
|
|
23
|
+
});
|
|
24
|
+
|
|
6
25
|
it('shares context storage across duplicate module instances', async () => {
|
|
7
26
|
// @ts-expect-error Vite treats the query as a distinct module instance.
|
|
8
27
|
let duplicateHook: typeof import('./hook') = await import('./hook?duplicate-instance');
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { resolveDefaultExport } from './resolveDefaultExport';
|
|
3
|
+
|
|
4
|
+
class Example {
|
|
5
|
+
value: number;
|
|
6
|
+
constructor(value: number) {
|
|
7
|
+
this.value = value;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
describe('resolveDefaultExport', () => {
|
|
12
|
+
it('returns a constructor export as-is', () => {
|
|
13
|
+
expect(resolveDefaultExport<typeof Example>(Example)).toBe(Example);
|
|
14
|
+
expect(new (resolveDefaultExport<typeof Example>(Example))(1).value).toBe(1);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('unwraps CJS default-export objects produced by bundlers', () => {
|
|
18
|
+
expect(resolveDefaultExport<typeof Example>({ default: Example })).toBe(Example);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('unwraps nested default exports from double-bundling', () => {
|
|
22
|
+
expect(
|
|
23
|
+
resolveDefaultExport<typeof Example>({ default: { default: Example } })
|
|
24
|
+
).toBe(Example);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('throws when the export is not a constructor', () => {
|
|
28
|
+
expect(() => resolveDefaultExport({})).toThrow(TypeError);
|
|
29
|
+
expect(() => resolveDefaultExport({ default: { foo: 1 } })).toThrow(TypeError);
|
|
30
|
+
expect(() => resolveDefaultExport(undefined)).toThrow(TypeError);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export let resolveDefaultExport = <T>(value: unknown): T => {
|
|
2
|
+
let current = value;
|
|
3
|
+
|
|
4
|
+
for (let i = 0; i < 4; i++) {
|
|
5
|
+
if (typeof current === 'function') return current as T;
|
|
6
|
+
if (current && typeof current === 'object' && 'default' in current) {
|
|
7
|
+
current = (current as { default: unknown }).default;
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
break;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
throw new TypeError('Module export is not a constructor');
|
|
14
|
+
};
|