@pstdio/sdk 0.23.0 → 0.24.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/dist/api/index.js +3 -0
- package/dist/api.d.ts +19 -0
- package/dist/client.d.ts +12 -0
- package/dist/data/index.js +115 -0
- package/dist/data.d.ts +47 -0
- package/dist/extensions/index.js +5 -1
- package/dist/extensions.d.ts +18 -0
- package/dist/hooks.d.ts +12 -0
- package/dist/resources/index.js +3 -0
- package/dist/resources.d.ts +4 -0
- package/dist/testing/index.js +222 -0
- package/dist/testing.d.ts +910 -0
- package/package.json +9 -1
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __returnValue = (v) => v;
|
|
3
|
+
function __exportSetter(name, newValue) {
|
|
4
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
5
|
+
}
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
set: __exportSetter.bind(all, name)
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// src/testing/memory-resources.ts
|
|
17
|
+
var createMemoryResources = (prefixes, sequences = new Map) => ({
|
|
18
|
+
allocate: async ({ kind }) => {
|
|
19
|
+
const prefix = prefixes[kind];
|
|
20
|
+
if (!prefix)
|
|
21
|
+
throw new Error(`Undeclared resource kind: ${kind}`);
|
|
22
|
+
const next = (sequences.get(kind) ?? 0) + 1;
|
|
23
|
+
sequences.set(kind, next);
|
|
24
|
+
return { id: crypto.randomUUID(), shorthand: `${prefix}-${next}` };
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// src/testing/command-context.ts
|
|
29
|
+
var sequencesByStorage = new WeakMap;
|
|
30
|
+
var paramsByContext = new WeakMap;
|
|
31
|
+
var makeCommandContext = (input) => {
|
|
32
|
+
const { storage, params, projectId = "proj-1", overrides } = input;
|
|
33
|
+
let sequences = sequencesByStorage.get(storage);
|
|
34
|
+
if (!sequences) {
|
|
35
|
+
sequences = new Map;
|
|
36
|
+
sequencesByStorage.set(storage, sequences);
|
|
37
|
+
}
|
|
38
|
+
const resources = createMemoryResources(input.resourcePrefixes ?? {}, sequences);
|
|
39
|
+
const context = {
|
|
40
|
+
extensionId: "test.extension",
|
|
41
|
+
name: "test-extension",
|
|
42
|
+
projectId,
|
|
43
|
+
project: { id: projectId, name: "Test Project", shorthand: "T" },
|
|
44
|
+
storage,
|
|
45
|
+
resources,
|
|
46
|
+
invocation: { params },
|
|
47
|
+
events: { emit: async () => ({ delivered: 0 }) },
|
|
48
|
+
notify: { action: async () => ({}), dismiss: async () => [], resolve: async () => [], toast: async () => {} },
|
|
49
|
+
workspaces: { list: async () => [], get: async () => null, getByShorthand: async () => null },
|
|
50
|
+
sessions: { list: async () => [], listByWorkspace: async () => [], addAnchors: async () => {} },
|
|
51
|
+
...overrides
|
|
52
|
+
};
|
|
53
|
+
paramsByContext.set(context, params);
|
|
54
|
+
return context;
|
|
55
|
+
};
|
|
56
|
+
var commandParamsFor = (context) => paramsByContext.get(context);
|
|
57
|
+
var makeCommandArgs = (input) => [makeCommandContext(input), input.params];
|
|
58
|
+
// src/testing/memory-repo-files.ts
|
|
59
|
+
var createMemoryRepoFiles = () => {
|
|
60
|
+
const files = new Map;
|
|
61
|
+
const encoder = new TextEncoder;
|
|
62
|
+
const decoder = new TextDecoder;
|
|
63
|
+
return {
|
|
64
|
+
files,
|
|
65
|
+
exists: async (path) => files.has(path) || [...files.keys()].some((file) => file.startsWith(`${path}/`)),
|
|
66
|
+
readText: async (path) => {
|
|
67
|
+
const value = files.get(path);
|
|
68
|
+
if (value === undefined)
|
|
69
|
+
throw new Error(`File not found: ${path}`);
|
|
70
|
+
return decoder.decode(value);
|
|
71
|
+
},
|
|
72
|
+
writeText: async (path, value) => {
|
|
73
|
+
files.set(path, encoder.encode(value));
|
|
74
|
+
},
|
|
75
|
+
readBytes: async (path) => {
|
|
76
|
+
const value = files.get(path);
|
|
77
|
+
if (value === undefined)
|
|
78
|
+
throw new Error(`File not found: ${path}`);
|
|
79
|
+
return value;
|
|
80
|
+
},
|
|
81
|
+
writeBytes: async (path, value) => {
|
|
82
|
+
files.set(path, value);
|
|
83
|
+
},
|
|
84
|
+
list: async (pattern) => {
|
|
85
|
+
const prefix = pattern ? pattern.replace(/\*+.*/, "") : "";
|
|
86
|
+
return [...files.keys()].filter((path) => path.startsWith(prefix)).sort().map((path) => ({ path }));
|
|
87
|
+
},
|
|
88
|
+
listDirs: async () => [],
|
|
89
|
+
delete: async (path) => {
|
|
90
|
+
const matches = [...files.keys()].filter((file) => file === path || file.startsWith(`${path}/`));
|
|
91
|
+
if (matches.length === 0)
|
|
92
|
+
throw Object.assign(new Error(`ENOENT: ${path}`), { code: "ENOENT" });
|
|
93
|
+
for (const file of matches)
|
|
94
|
+
files.delete(file);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
// src/testing/memory-storage.ts
|
|
99
|
+
var createMemoryStorage = () => {
|
|
100
|
+
const kv = new Map;
|
|
101
|
+
const collections = new Map;
|
|
102
|
+
const blobStores = new Map;
|
|
103
|
+
const collectionStore = (name) => {
|
|
104
|
+
const existing = collections.get(name);
|
|
105
|
+
if (existing)
|
|
106
|
+
return existing;
|
|
107
|
+
const created = new Map;
|
|
108
|
+
collections.set(name, created);
|
|
109
|
+
return created;
|
|
110
|
+
};
|
|
111
|
+
const blobStore = (name) => {
|
|
112
|
+
const existing = blobStores.get(name);
|
|
113
|
+
if (existing)
|
|
114
|
+
return existing;
|
|
115
|
+
const created = new Map;
|
|
116
|
+
blobStores.set(name, created);
|
|
117
|
+
return created;
|
|
118
|
+
};
|
|
119
|
+
const blobsApi = (name) => {
|
|
120
|
+
const store = blobStore(name);
|
|
121
|
+
return {
|
|
122
|
+
async put(input) {
|
|
123
|
+
const id = crypto.randomUUID();
|
|
124
|
+
const data = input.data instanceof Uint8Array ? input.data : new Uint8Array(input.data);
|
|
125
|
+
const ref = {
|
|
126
|
+
id,
|
|
127
|
+
name: input.name,
|
|
128
|
+
mimeType: input.mimeType ?? null,
|
|
129
|
+
size: data.byteLength,
|
|
130
|
+
hash: null,
|
|
131
|
+
url: `memory://${id}`,
|
|
132
|
+
createdAt: new Date().toISOString(),
|
|
133
|
+
updatedAt: new Date().toISOString()
|
|
134
|
+
};
|
|
135
|
+
store.set(id, { ...ref, data });
|
|
136
|
+
return ref;
|
|
137
|
+
},
|
|
138
|
+
async get(id) {
|
|
139
|
+
const stored = store.get(id);
|
|
140
|
+
if (!stored)
|
|
141
|
+
return;
|
|
142
|
+
const { data: _data, ...ref } = stored;
|
|
143
|
+
return ref;
|
|
144
|
+
},
|
|
145
|
+
async getBytes(id) {
|
|
146
|
+
const stored = store.get(id);
|
|
147
|
+
if (!stored)
|
|
148
|
+
throw new Error(`File not found: ${id}`);
|
|
149
|
+
return stored.data;
|
|
150
|
+
},
|
|
151
|
+
async list() {
|
|
152
|
+
return [...store.values()].map(({ data: _data, ...ref }) => ref);
|
|
153
|
+
},
|
|
154
|
+
async delete(id) {
|
|
155
|
+
store.delete(id);
|
|
156
|
+
},
|
|
157
|
+
urlFor(id) {
|
|
158
|
+
return `memory://${id}`;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
const api = {
|
|
163
|
+
files: blobsApi("project"),
|
|
164
|
+
scope(_scope) {
|
|
165
|
+
return api;
|
|
166
|
+
},
|
|
167
|
+
async get(key) {
|
|
168
|
+
return kv.get(key);
|
|
169
|
+
},
|
|
170
|
+
async set(key, value) {
|
|
171
|
+
kv.set(key, value);
|
|
172
|
+
},
|
|
173
|
+
async delete(key) {
|
|
174
|
+
kv.delete(key);
|
|
175
|
+
},
|
|
176
|
+
collection(name) {
|
|
177
|
+
const store = collectionStore(name);
|
|
178
|
+
return {
|
|
179
|
+
async get(id) {
|
|
180
|
+
return store.get(id);
|
|
181
|
+
},
|
|
182
|
+
async list() {
|
|
183
|
+
return [...store.values()];
|
|
184
|
+
},
|
|
185
|
+
async put(id, value) {
|
|
186
|
+
store.set(id, value);
|
|
187
|
+
},
|
|
188
|
+
async createIfAbsent(id, value) {
|
|
189
|
+
if (store.has(id))
|
|
190
|
+
return false;
|
|
191
|
+
store.set(id, value);
|
|
192
|
+
return true;
|
|
193
|
+
},
|
|
194
|
+
async deleteIfValue(id, value) {
|
|
195
|
+
if (store.get(id) !== value && JSON.stringify(store.get(id)) !== JSON.stringify(value))
|
|
196
|
+
return false;
|
|
197
|
+
return store.delete(id);
|
|
198
|
+
},
|
|
199
|
+
async create(value) {
|
|
200
|
+
const id = crypto.randomUUID();
|
|
201
|
+
store.set(id, value);
|
|
202
|
+
return { ...typeof value === "object" && value !== null ? value : {}, id };
|
|
203
|
+
},
|
|
204
|
+
async delete(id) {
|
|
205
|
+
store.delete(id);
|
|
206
|
+
},
|
|
207
|
+
attachments(itemId) {
|
|
208
|
+
return blobsApi(`${name}:${itemId}`);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
return api;
|
|
214
|
+
};
|
|
215
|
+
export {
|
|
216
|
+
makeCommandContext,
|
|
217
|
+
makeCommandArgs,
|
|
218
|
+
createMemoryStorage,
|
|
219
|
+
createMemoryResources,
|
|
220
|
+
createMemoryRepoFiles,
|
|
221
|
+
commandParamsFor
|
|
222
|
+
};
|