primitive-functions 0.3.0-alpha.8 → 0.3.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/index.js CHANGED
@@ -33,6 +33,72 @@ export function defineFunction(_keyOrHandler, _maybeHandler) {
33
33
  throw new Error(NOT_PROVIDED);
34
34
  }
35
35
 
36
+ /**
37
+ * The decisions an object form's `authorize` returns — `allow(resolved?)`
38
+ * and `deny(code, message?, { expose? })`. The platform copy builds them;
39
+ * this one refuses, like every other function here.
40
+ */
41
+ export function allow(_resolved) {
42
+ throw new Error(NOT_PROVIDED);
43
+ }
44
+
45
+ export function deny(_code, _message, _options) {
46
+ throw new Error(NOT_PROVIDED);
47
+ }
48
+
49
+ /**
50
+ * A handler's own failure code, `fail(code, message?)`, and the helpers that
51
+ * build an `authorize` — #4721. The platform copy implements them; these
52
+ * refuse, like every other function here.
53
+ */
54
+ export function fail(_code, _message) {
55
+ throw new Error(NOT_PROVIDED);
56
+ }
57
+
58
+ export function allowAnyone() {
59
+ throw new Error(NOT_PROVIDED);
60
+ }
61
+
62
+ export function allowCallers(_rules) {
63
+ throw new Error(NOT_PROVIDED);
64
+ }
65
+
66
+ export function requireSignedIn() {
67
+ throw new Error(NOT_PROVIDED);
68
+ }
69
+
70
+ export function requireRole(_role) {
71
+ throw new Error(NOT_PROVIDED);
72
+ }
73
+
74
+ export function requireMember(_groupIdOf, _role) {
75
+ throw new Error(NOT_PROVIDED);
76
+ }
77
+
78
+ export function requireCollectionRole(_collectionIdOf, _minRole) {
79
+ throw new Error(NOT_PROVIDED);
80
+ }
81
+
82
+ export function requireDocumentOwner(_documentIdOf) {
83
+ throw new Error(NOT_PROVIDED);
84
+ }
85
+
86
+ export function requirePublicDb3(_db3IdOf, _type) {
87
+ throw new Error(NOT_PROVIDED);
88
+ }
89
+
90
+ export function requireDb3Level(_db3IdOf, _type, _minLevel, _options) {
91
+ throw new Error(NOT_PROVIDED);
92
+ }
93
+
94
+ export function requireToken(_tokenOf) {
95
+ throw new Error(NOT_PROVIDED);
96
+ }
97
+
98
+ export function requireInvitation(_tokenOf) {
99
+ throw new Error(NOT_PROVIDED);
100
+ }
101
+
36
102
  /**
37
103
  * The platform's cap on a registered query's cache TTL. The stub carries the
38
104
  * value rather than throwing, because it is a constant an author may read at
@@ -63,6 +129,31 @@ export function ulid() {
63
129
  throw new Error(NOT_PROVIDED);
64
130
  }
65
131
 
132
+ /** A vector's numbers as a db3 vector field's stored base64. The platform copy encodes; this refuses. */
133
+ export function encodeVector() {
134
+ throw new Error(NOT_PROVIDED);
135
+ }
136
+
137
+ /** A stored vector's numbers. The platform copy decodes; this refuses. */
138
+ export function decodeVector() {
139
+ throw new Error(NOT_PROVIDED);
140
+ }
141
+
142
+ /** A stored vector's raw bytes. The platform copy reads them; this refuses. */
143
+ export function vectorBytes() {
144
+ throw new Error(NOT_PROVIDED);
145
+ }
146
+
147
+ /** A value as a db3 JSON field's canonical text. The platform copy encodes; this refuses. */
148
+ export function encodeDb3Json() {
149
+ throw new Error(NOT_PROVIDED);
150
+ }
151
+
152
+ /** A db3 JSON field's stored text as its value. The platform copy decodes; this refuses. */
153
+ export function decodeDb3Json() {
154
+ throw new Error(NOT_PROVIDED);
155
+ }
156
+
66
157
  /**
67
158
  * The per-family durable step policies. The stub carries an empty shape rather
68
159
  * than throwing: it is read at module scope by code that only type-checks.
@@ -123,10 +214,29 @@ export function assertTrigger() {
123
214
  export default {
124
215
  SDK_STUB_VERSION,
125
216
  defineFunction,
217
+ allow,
218
+ deny,
219
+ fail,
220
+ allowAnyone,
221
+ allowCallers,
222
+ requireSignedIn,
223
+ requireRole,
224
+ requireMember,
225
+ requireCollectionRole,
226
+ requireDocumentOwner,
227
+ requirePublicDb3,
228
+ requireDb3Level,
229
+ requireToken,
230
+ requireInvitation,
126
231
  defineQuery,
127
232
  defineMutation,
128
233
  pMap,
129
234
  ulid,
235
+ encodeVector,
236
+ decodeVector,
237
+ vectorBytes,
238
+ encodeDb3Json,
239
+ decodeDb3Json,
130
240
  assertRuntime,
131
241
  assertTrigger,
132
242
  FunctionRuntimeError,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "primitive-functions",
3
- "version": "0.3.0-alpha.8",
4
- "description": "The module a Primitive server function imports. Supplied by the platform at invoke time; reserved here so the name is ours before the runtime lands.",
3
+ "version": "0.3.0",
4
+ "description": "The module a Primitive server function imports, supplied by the platform at invoke time, and test doubles for its context and step (primitive-functions/testing).",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Primitive LLC",
7
7
  "type": "module",
@@ -12,11 +12,19 @@
12
12
  "types": "./index.d.ts",
13
13
  "import": "./index.js",
14
14
  "default": "./index.js"
15
+ },
16
+ "./testing": {
17
+ "types": "./testing.d.ts",
18
+ "import": "./testing.js",
19
+ "default": "./testing.js"
15
20
  }
16
21
  },
17
22
  "files": [
18
23
  "index.js",
19
24
  "index.d.ts",
25
+ "testing.js",
26
+ "testing.d.ts",
27
+ "testing-members.generated.js",
20
28
  "README.md"
21
29
  ],
22
30
  "publishConfig": {
@@ -0,0 +1,487 @@
1
+ // GENERATED by `pnpm functions:profile` (scripts/generate-function-profile.mjs)
2
+ // from the `primitive-functions` authoring types. Do not edit.
3
+ //
4
+ // Every member of `FunctionContext` and `FunctionStep`, for the test doubles in
5
+ // `testing.js`: "fn" is a function, "data" a required data member, "data?" an
6
+ // optional one, and a nested object a namespace.
7
+
8
+ export const TEST_MEMBERS = {
9
+ "ctx": {
10
+ "user": "data",
11
+ "trigger": "data",
12
+ "tool": "data?",
13
+ "runtime": "data",
14
+ "actionTokens": {
15
+ "sign": "fn"
16
+ },
17
+ "runId": "data",
18
+ "sliceId": "data",
19
+ "api": {
20
+ "agentSessions": {
21
+ "addMember": "fn",
22
+ "answer": "fn",
23
+ "attachArtifact": "fn",
24
+ "attachments": {
25
+ "downloadHeaders": "fn",
26
+ "download": "fn",
27
+ "upload": "fn"
28
+ },
29
+ "cancel": "fn",
30
+ "create": "fn",
31
+ "delete": "fn",
32
+ "get": "fn",
33
+ "list": "fn",
34
+ "markRead": "fn",
35
+ "recordEvent": "fn",
36
+ "removeMember": "fn",
37
+ "rename": "fn",
38
+ "send": "fn"
39
+ },
40
+ "analytics": {
41
+ "cohortRetention": "fn",
42
+ "dailyActive": "fn",
43
+ "db3Queries": "fn",
44
+ "errorGroups": "fn",
45
+ "integrationUsage": "fn",
46
+ "listEvents": "fn",
47
+ "listEventsGrouped": "fn",
48
+ "overviewDau": "fn",
49
+ "overviewGrowth": "fn",
50
+ "overviewMau": "fn",
51
+ "overviewWau": "fn",
52
+ "requests": "fn",
53
+ "rollingActive": "fn",
54
+ "searchUsers": "fn",
55
+ "topPrompts": "fn",
56
+ "topUsers": "fn",
57
+ "userDetail": "fn",
58
+ "userSnapshot": "fn",
59
+ "writeForUser": "fn"
60
+ },
61
+ "blobBuckets": {
62
+ "createBucket": "fn",
63
+ "delete": "fn",
64
+ "deleteBatch": "fn",
65
+ "deleteBucket": "fn",
66
+ "download": "fn",
67
+ "downloadHeaders": "fn",
68
+ "downloadSigned": "fn",
69
+ "get": "fn",
70
+ "getBucket": "fn",
71
+ "getSignedUrl": "fn",
72
+ "getSignedUrls": "fn",
73
+ "list": "fn",
74
+ "listBuckets": "fn",
75
+ "updateBucket": "fn",
76
+ "upload": "fn"
77
+ },
78
+ "channels": {
79
+ "authorize": "fn",
80
+ "publish": "fn"
81
+ },
82
+ "collections": {
83
+ "addDocument": "fn",
84
+ "addMember": "fn",
85
+ "create": "fn",
86
+ "delete": "fn",
87
+ "get": "fn",
88
+ "getAccess": "fn",
89
+ "grantGroupPermission": "fn",
90
+ "list": "fn",
91
+ "listByCustodian": "fn",
92
+ "listCollectionsForDocument": "fn",
93
+ "listDb3": "fn",
94
+ "listDocuments": "fn",
95
+ "listForUser": "fn",
96
+ "listMembers": "fn",
97
+ "listPendingInvitations": "fn",
98
+ "removeDocument": "fn",
99
+ "removeMember": "fn",
100
+ "resolveRole": "fn",
101
+ "revokeGroupPermission": "fn",
102
+ "revokePendingInvitation": "fn",
103
+ "setMemberRole": "fn",
104
+ "transfer": "fn",
105
+ "update": "fn"
106
+ },
107
+ "configVars": {
108
+ "get": "fn"
109
+ },
110
+ "connections": {
111
+ "send": "fn"
112
+ },
113
+ "databaseTypeConfigs": {
114
+ "create": "fn",
115
+ "delete": "fn",
116
+ "get": "fn",
117
+ "getReindexStatus": "fn",
118
+ "list": "fn",
119
+ "scaffoldSchema": "fn",
120
+ "update": "fn"
121
+ },
122
+ "databases": {
123
+ "addManager": "fn",
124
+ "create": "fn",
125
+ "delete": "fn",
126
+ "get": "fn",
127
+ "grantGroupPermission": "fn",
128
+ "list": "fn",
129
+ "listGroupPermissions": "fn",
130
+ "listPermissions": "fn",
131
+ "records": {
132
+ "addToSet": "fn",
133
+ "aggregate": "fn",
134
+ "batch": "fn",
135
+ "count": "fn",
136
+ "delete": "fn",
137
+ "describe": "fn",
138
+ "dropIndex": "fn",
139
+ "dropUniqueConstraint": "fn",
140
+ "increment": "fn",
141
+ "listIndexes": "fn",
142
+ "listUniqueConstraints": "fn",
143
+ "models": "fn",
144
+ "patch": "fn",
145
+ "query": "fn",
146
+ "registerIndex": "fn",
147
+ "registerUniqueConstraint": "fn",
148
+ "removeFromSet": "fn",
149
+ "save": "fn",
150
+ "syncIndexes": "fn"
151
+ },
152
+ "reindex": "fn",
153
+ "revokeGroupPermission": "fn",
154
+ "revokeGroupPermissionByType": "fn",
155
+ "revokePermission": "fn",
156
+ "transferOwnership": "fn",
157
+ "update": "fn"
158
+ },
159
+ "db3": {
160
+ "abortIngest": "fn",
161
+ "addTag": "fn",
162
+ "aliases": {
163
+ "delete": "fn",
164
+ "listForDocument": "fn",
165
+ "resolve": "fn",
166
+ "set": "fn"
167
+ },
168
+ "approveAccessRequest": "fn",
169
+ "blobs": {
170
+ "delete": "fn",
171
+ "deleteBatch": "fn",
172
+ "downloadHeaders": "fn",
173
+ "downloadPublic": "fn",
174
+ "downloadSigned": "fn",
175
+ "download": "fn",
176
+ "get": "fn",
177
+ "getSignedUrls": "fn",
178
+ "list": "fn",
179
+ "signedUploadUrl": "fn",
180
+ "upload": "fn"
181
+ },
182
+ "clearLinkAccess": "fn",
183
+ "commitIngest": "fn",
184
+ "create": "fn",
185
+ "createIngest": "fn",
186
+ "delete": "fn",
187
+ "denyAccessRequest": "fn",
188
+ "exportChain": "fn",
189
+ "get": "fn",
190
+ "getAppAccess": "fn",
191
+ "getIngest": "fn",
192
+ "getLinkAccess": "fn",
193
+ "getOrCreateWithAlias": "fn",
194
+ "getPermissions": "fn",
195
+ "getSchema": "fn",
196
+ "getSnapshot": "fn",
197
+ "getStats": "fn",
198
+ "getSync": "fn",
199
+ "getType": "fn",
200
+ "grantGroupPermission": "fn",
201
+ "indexes": {
202
+ "drop": "fn",
203
+ "list": "fn",
204
+ "model": {
205
+ "delete": "fn",
206
+ "get": "fn",
207
+ "upload": "fn"
208
+ },
209
+ "register": "fn"
210
+ },
211
+ "listAccessRequests": "fn",
212
+ "listGroupPermissions": "fn",
213
+ "listHeldByUser": "fn",
214
+ "listIngests": "fn",
215
+ "listPendingInvitations": "fn",
216
+ "listSharedWithUser": "fn",
217
+ "listSnapshots": "fn",
218
+ "parallel": "fn",
219
+ "records": {
220
+ "aggregate": "fn",
221
+ "batch": "fn",
222
+ "batchRead": "fn",
223
+ "count": "fn",
224
+ "delete": "fn",
225
+ "deleteWhere": "fn",
226
+ "explain": "fn",
227
+ "increment": "fn",
228
+ "patch": "fn",
229
+ "patchWhere": "fn",
230
+ "query": "fn",
231
+ "save": "fn"
232
+ },
233
+ "removePermissionByEmail": "fn",
234
+ "removePermissionByUserId": "fn",
235
+ "removeTag": "fn",
236
+ "requestAccess": "fn",
237
+ "requestSnapshot": "fn",
238
+ "revokeGroupPermission": "fn",
239
+ "revokePendingInvitation": "fn",
240
+ "room": "fn",
241
+ "setAppAccess": "fn",
242
+ "setLinkAccess": "fn",
243
+ "setOwnerRow": "fn",
244
+ "setPublicAccess": "fn",
245
+ "setSync": "fn",
246
+ "setType": "fn",
247
+ "transfer": "fn",
248
+ "update": "fn",
249
+ "updatePermissions": "fn",
250
+ "uploadIngestChunk": "fn",
251
+ "validateAccess": "fn"
252
+ },
253
+ "documents": {
254
+ "abortIngest": "fn",
255
+ "addTag": "fn",
256
+ "aliases": {
257
+ "delete": "fn",
258
+ "listForDocument": "fn",
259
+ "resolve": "fn",
260
+ "set": "fn"
261
+ },
262
+ "approveAccessRequest": "fn",
263
+ "blobs": {
264
+ "delete": "fn",
265
+ "downloadHeaders": "fn",
266
+ "download": "fn",
267
+ "get": "fn",
268
+ "list": "fn",
269
+ "upload": "fn"
270
+ },
271
+ "clearLinkAccess": "fn",
272
+ "commitIngest": "fn",
273
+ "create": "fn",
274
+ "createIngest": "fn",
275
+ "createWithAlias": "fn",
276
+ "debugDumpUpdates": "fn",
277
+ "debugMerge": "fn",
278
+ "debugMergeBlock": "fn",
279
+ "debugRestore": "fn",
280
+ "debugStats": "fn",
281
+ "delete": "fn",
282
+ "denyAccessRequest": "fn",
283
+ "exportChain": "fn",
284
+ "exportState": "fn",
285
+ "get": "fn",
286
+ "getImportChainStatus": "fn",
287
+ "getIngest": "fn",
288
+ "getLinkAccess": "fn",
289
+ "getOrCreateWithAlias": "fn",
290
+ "getPermissions": "fn",
291
+ "getSchema": "fn",
292
+ "getSnapshot": "fn",
293
+ "getStats": "fn",
294
+ "grantGroupPermission": "fn",
295
+ "importChain": "fn",
296
+ "importChainArtifact": "fn",
297
+ "importState": "fn",
298
+ "listAccessRequests": "fn",
299
+ "listGroupPermissions": "fn",
300
+ "listIngests": "fn",
301
+ "listOwnedByUser": "fn",
302
+ "listPendingInvitations": "fn",
303
+ "listSharedWithUser": "fn",
304
+ "listSnapshots": "fn",
305
+ "open": "fn",
306
+ "records": {
307
+ "aggregate": "fn",
308
+ "batch": "fn",
309
+ "count": "fn",
310
+ "delete": "fn",
311
+ "patch": "fn",
312
+ "query": "fn",
313
+ "save": "fn"
314
+ },
315
+ "removePermissionByEmail": "fn",
316
+ "removePermissionByUserId": "fn",
317
+ "removeTag": "fn",
318
+ "requestAccess": "fn",
319
+ "requestSnapshot": "fn",
320
+ "revokeGroupPermission": "fn",
321
+ "revokeGroupPermissionByType": "fn",
322
+ "revokePendingInvitation": "fn",
323
+ "room": "fn",
324
+ "setLinkAccess": "fn",
325
+ "transferOwnership": "fn",
326
+ "update": "fn",
327
+ "updatePermissions": "fn",
328
+ "uploadIngestChunk": "fn",
329
+ "validateAccess": "fn"
330
+ },
331
+ "email": {
332
+ "send": "fn"
333
+ },
334
+ "functions": {
335
+ "getStatus": "fn",
336
+ "getStatusByRunKey": "fn",
337
+ "invoke": "fn",
338
+ "invokeAsSystem": "fn",
339
+ "listRunSteps": "fn",
340
+ "listRuns": "fn",
341
+ "logs": "fn",
342
+ "start": "fn",
343
+ "startAsSystem": "fn",
344
+ "terminate": "fn"
345
+ },
346
+ "groups": {
347
+ "addMember": "fn",
348
+ "addMemberByType": "fn",
349
+ "create": "fn",
350
+ "delete": "fn",
351
+ "deleteByType": "fn",
352
+ "get": "fn",
353
+ "getByType": "fn",
354
+ "list": "fn",
355
+ "listByCustodian": "fn",
356
+ "listDatabases": "fn",
357
+ "listDatabasesByType": "fn",
358
+ "listDb3": "fn",
359
+ "listDb3ByType": "fn",
360
+ "listDocuments": "fn",
361
+ "listDocumentsByType": "fn",
362
+ "listMembers": "fn",
363
+ "listMembersByType": "fn",
364
+ "listPendingInvitations": "fn",
365
+ "listPendingInvitationsByType": "fn",
366
+ "listUserMemberships": "fn",
367
+ "removeMember": "fn",
368
+ "removeMemberByEmail": "fn",
369
+ "removeMemberByEmailByType": "fn",
370
+ "removeMemberByType": "fn",
371
+ "revokePendingInvitation": "fn",
372
+ "revokePendingInvitationByType": "fn",
373
+ "setMemberRole": "fn",
374
+ "transfer": "fn",
375
+ "update": "fn",
376
+ "updateByType": "fn"
377
+ },
378
+ "integrations": {
379
+ "call": "fn",
380
+ "list": "fn"
381
+ },
382
+ "invitations": {
383
+ "accept": "fn",
384
+ "create": "fn",
385
+ "delete": "fn",
386
+ "get": "fn",
387
+ "getBy": "fn",
388
+ "list": "fn",
389
+ "quota": "fn"
390
+ },
391
+ "locks": {
392
+ "forceRelease": "fn",
393
+ "list": "fn",
394
+ "release": "fn",
395
+ "renew": "fn",
396
+ "status": "fn",
397
+ "tryAcquire": "fn"
398
+ },
399
+ "prompts": {
400
+ "run": "fn"
401
+ },
402
+ "secrets": {
403
+ "get": "fn"
404
+ },
405
+ "usage": {
406
+ "forUser": "fn"
407
+ },
408
+ "users": {
409
+ "aggregate": "fn",
410
+ "count": "fn",
411
+ "forEachBatch": "fn",
412
+ "get": "fn",
413
+ "getBasic": "fn",
414
+ "getBy": "fn",
415
+ "getProfiles": "fn",
416
+ "getRootDocument": "fn",
417
+ "list": "fn",
418
+ "lookup": "fn",
419
+ "query": "fn",
420
+ "remove": "fn",
421
+ "send": "fn",
422
+ "setProfile": "fn",
423
+ "setProperties": "fn",
424
+ "setRole": "fn"
425
+ }
426
+ },
427
+ "db": "fn",
428
+ "db3": "fn",
429
+ "doc": "fn",
430
+ "integrations": {
431
+ "call": "fn"
432
+ },
433
+ "functions": {
434
+ "start": "fn"
435
+ },
436
+ "prompts": {
437
+ "run": "fn"
438
+ },
439
+ "agents": {
440
+ "createSession": "fn",
441
+ "getSession": "fn",
442
+ "listSessions": "fn",
443
+ "recordEvent": "fn",
444
+ "deleteSession": "fn"
445
+ },
446
+ "usage": {
447
+ "forUser": "fn"
448
+ },
449
+ "secret": "fn",
450
+ "configVar": "fn",
451
+ "users": {
452
+ "list": "fn",
453
+ "iterate": "fn",
454
+ "query": "fn",
455
+ "count": "fn",
456
+ "aggregate": "fn",
457
+ "forEachBatch": "fn",
458
+ "send": "fn",
459
+ "get": "fn",
460
+ "getBy": "fn",
461
+ "setProperties": "fn",
462
+ "addToSet": "fn",
463
+ "removeFromSet": "fn"
464
+ },
465
+ "invitations": {
466
+ "getBy": "fn"
467
+ },
468
+ "connections": {
469
+ "send": "fn"
470
+ },
471
+ "channels": {
472
+ "authorize": "fn",
473
+ "publish": "fn"
474
+ },
475
+ "locks": {
476
+ "acquire": "fn",
477
+ "release": "fn",
478
+ "withLock": "fn"
479
+ }
480
+ },
481
+ "step": {
482
+ "do": "fn",
483
+ "sleep": "fn",
484
+ "sleepUntil": "fn",
485
+ "waitForEvent": "fn"
486
+ }
487
+ };