primitive-functions 0.2.0-alpha.0 → 0.2.0-alpha.10

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.
Files changed (3) hide show
  1. package/index.d.ts +1697 -35
  2. package/index.js +92 -4
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -24,11 +24,99 @@ const NOT_PROVIDED =
24
24
  export const SDK_STUB_VERSION = "0.0.1";
25
25
 
26
26
  /**
27
- * Declare a function's handler. The platform copy returns the handler wrapped
28
- * with its invocation context; this one refuses, loudly.
27
+ * Declare a function's handler — `defineFunction(handler)` or the keyed
28
+ * `defineFunction("<key>", handler)`. The platform copy returns the handler
29
+ * wrapped with its invocation context; this one refuses, loudly, whichever
30
+ * shape it is called with.
29
31
  */
30
- export function defineFunction() {
32
+ export function defineFunction(_keyOrHandler, _maybeHandler) {
31
33
  throw new Error(NOT_PROVIDED);
32
34
  }
33
35
 
34
- export default { SDK_STUB_VERSION, defineFunction };
36
+ /**
37
+ * The platform's cap on a registered query's cache TTL. The stub carries the
38
+ * value rather than throwing, because it is a constant an author may read at
39
+ * module scope while type-checking outside a sandbox.
40
+ */
41
+ export const MAX_QUERY_CACHE_TTL_MS = 60000;
42
+
43
+ /**
44
+ * Register a named query or mutation (#3187). Same reason as above: an ESM
45
+ * named import of an export a module does not have is a LINK error, so the
46
+ * stub must declare every export the platform copy has — and refuse.
47
+ */
48
+ export function defineQuery() {
49
+ throw new Error(NOT_PROVIDED);
50
+ }
51
+
52
+ export function defineMutation() {
53
+ throw new Error(NOT_PROVIDED);
54
+ }
55
+
56
+ /** Bounded-concurrency map. The platform copy implements it; this refuses. */
57
+ export function pMap() {
58
+ throw new Error(NOT_PROVIDED);
59
+ }
60
+
61
+ /** A time-ordered ULID, minted by the platform copy. */
62
+ export function ulid() {
63
+ throw new Error(NOT_PROVIDED);
64
+ }
65
+
66
+ /**
67
+ * The per-family durable step policies. The stub carries an empty shape rather
68
+ * than throwing: it is read at module scope by code that only type-checks.
69
+ */
70
+ export const PMAP_DEFAULT_CONCURRENCY = 8;
71
+
72
+ /**
73
+ * The per-family durable step policies. The stub carries the SHAPE and empty
74
+ * values: an author may read `stepPolicy.email` at module scope while
75
+ * type-checking outside a sandbox, and throwing there would break a build that
76
+ * never runs a function. The platform copy carries the runners' real numbers.
77
+ */
78
+ export const stepPolicy = {
79
+ email: null,
80
+ llm: null,
81
+ gemini: null,
82
+ database: null,
83
+ };
84
+
85
+ /**
86
+ * The runtime refusal's error class — #3482.
87
+ *
88
+ * Carried rather than thrown from: a function narrows a `catch` with
89
+ * `instanceof FunctionRuntimeError`, and a class that threw on construction
90
+ * would break a build that only type-checks. The platform copy is the one that
91
+ * is ever really thrown.
92
+ */
93
+ export class FunctionRuntimeError extends Error {
94
+ constructor(message, runtime, required) {
95
+ super(message);
96
+ this.name = "FUNCTION_RUNTIME_REFUSED";
97
+ this.runtime = runtime;
98
+ this.required = required;
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Refuse the runtime this function was not written for — #3482.
104
+ *
105
+ * The platform copy compares the required runtime against the one the isolate
106
+ * declared. This one refuses, loudly, like every other function here: an
107
+ * assertion answered outside a sandbox would be answering about nothing.
108
+ */
109
+ export function assertRuntime() {
110
+ throw new Error(NOT_PROVIDED);
111
+ }
112
+
113
+ export default {
114
+ SDK_STUB_VERSION,
115
+ defineFunction,
116
+ defineQuery,
117
+ defineMutation,
118
+ pMap,
119
+ ulid,
120
+ assertRuntime,
121
+ FunctionRuntimeError,
122
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "primitive-functions",
3
- "version": "0.2.0-alpha.0",
3
+ "version": "0.2.0-alpha.10",
4
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.",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Primitive LLC",