@sequenceholdings/managed-functions 0.3.5 → 0.4.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/README.md CHANGED
@@ -13,6 +13,29 @@ function consumer or branch on a function ID.
13
13
 
14
14
  ## ORM as the invoking user
15
15
 
16
+ ### Default SQL (planned SDK 0.4.0)
17
+
18
+ With the matching Atlas runtime, use the same caller-scoped executor without
19
+ an operation manifest:
20
+
21
+ ```ts
22
+ const orm = createFunctionOrmExecutor({ request, baseUrl: platformOrigin, namespace: 'lending' })
23
+ const result = await orm.sql({
24
+ sql: `SELECT l.id, c.name FROM lending.loans l
25
+ JOIN party.customers c ON c.id = l."customerId"`,
26
+ })
27
+ ```
28
+
29
+ The invocation still needs its existing declared data bindings covering every
30
+ read object, including policy dependencies. SQL does not grant extra access.
31
+ Namespace access, row policies, foreign exports and optional consumer contracts
32
+ remain enforced. Results contain `columns`, array-valued `rows`, and `truncated`;
33
+ numeric/bigint SQL results are always exact strings. Read-only SELECT queries
34
+ are bounded to 1,000 rows / 8 MiB. Source versions are not proof of publication
35
+ or server rollout; the registered-operation workflow below remains supported.
36
+
37
+ ### Registered operations
38
+
16
39
  Available in SDK **0.2.0 and later**. Install the SDK in the function package;
17
40
  the separate ORM authoring/compiler package is not needed in the deployed
18
41
  function. Copy the namespace's generated `operations.manifest.json` into that
package/dist/orm.d.ts CHANGED
@@ -15,6 +15,29 @@ declare class OrmOperationError extends OrmClientError {
15
15
  readonly name = "OrmOperationError";
16
16
  constructor(message: string, status: number | null, code: string | null, errors?: readonly OperationErrorEntry[]);
17
17
  }
18
+ type SqlQueryParameter = {
19
+ type: 'text' | 'uuid' | 'date' | 'timestamptz' | 'numeric' | 'bigint';
20
+ value: string | null;
21
+ } | {
22
+ type: 'integer' | 'double';
23
+ value: number | null;
24
+ } | {
25
+ type: 'boolean';
26
+ value: boolean | null;
27
+ };
28
+ type SqlQueryVariables = {
29
+ sql: string;
30
+ parameters?: Record<string, SqlQueryParameter>;
31
+ };
32
+ interface SqlQueryResult {
33
+ columns: Array<{
34
+ name: string;
35
+ type: string;
36
+ nullable: boolean;
37
+ }>;
38
+ rows: Array<Array<string | number | boolean | null>>;
39
+ truncated: boolean;
40
+ }
18
41
 
19
42
  /** One entry of `operations.manifest.json` (generated by `orm generate`). */
20
43
  interface ManifestOperation {
@@ -38,6 +61,11 @@ interface OperationExecutor {
38
61
  /** Execute a manifest operation by name (or a raw `sha256:` hash). */
39
62
  execute<TData = Record<string, unknown>>(op: string, variables?: Record<string, unknown>, options?: OperationExecutionOptions): Promise<TData>;
40
63
  }
64
+ /** Additive factory result; existing host wrappers implementing OperationExecutor remain valid. */
65
+ interface SqlOperationExecutor extends OperationExecutor {
66
+ /** Default read-only ontology SQL; no authored operation or manifest needed. */
67
+ sql(variables: SqlQueryVariables): Promise<SqlQueryResult>;
68
+ }
41
69
 
42
70
  type FunctionOrmErrorCode = 'INVALID_CONFIGURATION' | 'MISSING_CALLER_CONTEXT' | 'INVALID_CALLER_CONTEXT' | 'UNSUPPORTED_CALLER' | 'EXPIRED_CALLER_CONTEXT';
43
71
  declare class FunctionOrmError extends Error {
@@ -55,11 +83,11 @@ interface FunctionOrmExecutorOptions {
55
83
  request: FunctionOrmRequest;
56
84
  baseUrl: string;
57
85
  namespace: string;
58
- manifest: unknown;
86
+ manifest?: unknown;
59
87
  fetchImpl?: typeof globalThis.fetch;
60
88
  jsonScalars?: FunctionOrmJsonScalars;
61
89
  }
62
- declare function createFunctionOrmExecutor({ request, fetchImpl, ...options }: FunctionOrmExecutorOptions): OperationExecutor;
63
- declare function createFunctionServiceOrmExecutor({ request, fetchImpl, ...options }: FunctionOrmExecutorOptions): OperationExecutor;
90
+ declare function createFunctionOrmExecutor({ request, fetchImpl, ...options }: FunctionOrmExecutorOptions): SqlOperationExecutor;
91
+ declare function createFunctionServiceOrmExecutor({ request, fetchImpl, ...options }: FunctionOrmExecutorOptions): SqlOperationExecutor;
64
92
 
65
- export { FunctionOrmError, type FunctionOrmErrorCode, type FunctionOrmExecutorOptions, type FunctionOrmJsonScalars, type FunctionOrmRequest, ORM_JSON_SCALARS_HEADER, ORM_LOSSLESS_JSON_SCALARS, type OperationExecutor, type OperationsManifest, OrmClientError, OrmOperationError, createFunctionOrmExecutor, createFunctionServiceOrmExecutor };
93
+ export { FunctionOrmError, type FunctionOrmErrorCode, type FunctionOrmExecutorOptions, type FunctionOrmJsonScalars, type FunctionOrmRequest, ORM_JSON_SCALARS_HEADER, ORM_LOSSLESS_JSON_SCALARS, type OperationExecutor, type OperationsManifest, OrmClientError, OrmOperationError, type SqlOperationExecutor, createFunctionOrmExecutor, createFunctionServiceOrmExecutor };
package/dist/orm.js CHANGED
@@ -82,6 +82,7 @@ function readOperationResponse({
82
82
  }
83
83
  return payload.data;
84
84
  }
85
+ var BUILTIN_SQL_READ_HASH = "sha256:a50c477c952a5e0fe68ed158a4530e4aab573c09bcbb1a8ac454dc88a39a6258";
85
86
  function validateIdempotencyKey(key) {
86
87
  if (key !== void 0 && !/^[A-Za-z0-9._:-]{1,128}$/.test(key)) {
87
88
  throw new OrmClientError("idempotencyKey must be 1\u2013128 letters, digits, dots, underscores, colons or hyphens");
@@ -103,13 +104,13 @@ function readManifestHashes(manifest) {
103
104
  }
104
105
  function createOperationExecutorWithTransport({ namespace, manifest, transport }) {
105
106
  if (typeof namespace !== "string" || !NAMESPACE_PATTERN.test(namespace)) throw new OrmClientError("invalid ORM namespace \u2014 expected a lowercase identifier of at most 41 characters");
106
- const hashes = readManifestHashes(manifest);
107
+ const hashes = manifest === void 0 ? /* @__PURE__ */ new Map() : readManifestHashes(manifest);
107
108
  const knownHashes = new Set(hashes.values());
108
109
  async function execute(op, variables = {}, options = {}) {
109
110
  validateIdempotencyKey(options.idempotencyKey);
110
111
  if (typeof op !== "string" && op.namespace !== namespace) throw new OrmClientError("operation belongs to a different namespace");
111
112
  const selector = typeof op === "string" ? op : op.hash;
112
- const hash = hashes.get(selector) ?? (knownHashes.has(selector) ? selector : void 0);
113
+ const hash = selector === BUILTIN_SQL_READ_HASH ? selector : hashes.get(selector) ?? (knownHashes.has(selector) ? selector : void 0);
113
114
  if (!hash) throw new OrmClientError(`unknown operation "${op}" \u2014 not in the manifest (${hashes.size} known). Re-run seq-studio orm generate.`);
114
115
  if (!isRecord(variables)) throw new OrmClientError("operation variables must be an object");
115
116
  const response = await transport({
@@ -123,7 +124,7 @@ function createOperationExecutorWithTransport({ namespace, manifest, transport }
123
124
  }
124
125
  return readOperationResponse(response);
125
126
  }
126
- return { execute };
127
+ return { execute, sql: (variables) => execute(BUILTIN_SQL_READ_HASH, variables) };
127
128
  }
128
129
 
129
130
  // src/orm.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sequenceholdings/managed-functions",
3
- "version": "0.3.5",
3
+ "version": "0.4.0",
4
4
  "description": "Managed Function context and opt-in cache runtime",
5
5
  "license": "UNLICENSED",
6
6
  "main": "./dist/index.js",
@@ -48,7 +48,7 @@
48
48
  "vitest": "^4.1.11",
49
49
  "esbuild": "^0.25.0",
50
50
  "tsup": "^8.3.0",
51
- "@sequenceholdings/orm": "2.5.0"
51
+ "@sequenceholdings/orm": "2.6.0"
52
52
  },
53
53
  "engines": {
54
54
  "node": ">=20"