@segmentstream-cloud/app 0.13.1 → 0.13.2

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
@@ -263,7 +263,7 @@ Records, action inputs and action results are typed from the ontology:
263
263
  const { items, nextCursor } = await segmentstream.ontology.lead.find({
264
264
  where: { status: { in: ["new", "contacted"] } },
265
265
  orderBy: [{ field: "createdAt", direction: "desc" }],
266
- include: { owner: true },
266
+ include: ["owner"],
267
267
  limit: 20,
268
268
  });
269
269
  const lead = await segmentstream.ontology.lead.get(id);
@@ -279,6 +279,8 @@ const { result, validation, edits } = await segmentstream.ontology.lead.actions.
279
279
 
280
280
  - `find` sends the query as URL parameters, `query` as a JSON body; both return
281
281
  `{ items, nextCursor }`. Pass `nextCursor` as `after` for the next page.
282
+ - `include` adds related records under their relationship names: list the names,
283
+ `["owner", "tags"]`, or pass `{ owner: true, tags: true }`.
282
284
  - `actions.<name>(input, { validateOnly })` posts `{ input, options }` and returns
283
285
  `{ result, validation, edits }`. Generated actions are there too
284
286
  (`actions.create`, `update`, `delete`), and `action(name, input)` runs any action by
@@ -46,6 +46,11 @@ export declare function encodeWhere(input: {
46
46
  readonly getCatalog: () => Promise<WireCatalog>;
47
47
  }): Promise<Where | undefined>;
48
48
  export declare function queryToWire(query: OntologyQuery): unknown;
49
+ /**
50
+ * `include` with snake_case names, as an object: a list of names, `["assignedOwner"]`, becomes
51
+ * `{ assigned_owner: true }`, which every version of the ontology service accepts.
52
+ */
53
+ export declare function includeToWire(include: NonNullable<OntologyQuery["include"]>): Readonly<Record<string, unknown>>;
49
54
  /** Decode record fields and included relationships without descending into JSON properties. */
50
55
  export declare function recordFromWire<A = unknown>(value: unknown, entity: string, catalog: WireCatalog): A;
51
56
  export declare function actionInputToWire(input: unknown, entity: string, action: string, catalog: WireCatalog): unknown;
@@ -127,14 +127,23 @@ export function queryToWire(query) {
127
127
  ...(orderBy === undefined
128
128
  ? {}
129
129
  : { order_by: orderBy.map((order) => ({ ...order, field: toSnakeCase(order.field) })) }),
130
- ...(query.include === undefined
131
- ? {}
132
- : {
133
- include: Object.fromEntries(Object.entries(query.include).map(([name, value]) => [toSnakeCase(name), value])),
134
- }),
130
+ ...(query.include === undefined ? {} : { include: includeToWire(query.include) }),
135
131
  ...(where === undefined ? {} : { where }),
136
132
  };
137
133
  }
134
+ /**
135
+ * `include` with snake_case names, as an object: a list of names, `["assignedOwner"]`, becomes
136
+ * `{ assigned_owner: true }`, which every version of the ontology service accepts.
137
+ */
138
+ export function includeToWire(include) {
139
+ const entries = isIncludeList(include)
140
+ ? include.map((name) => [name, true])
141
+ : Object.entries(include);
142
+ return Object.fromEntries(entries.map(([name, value]) => [toSnakeCase(name), value]));
143
+ }
144
+ function isIncludeList(include) {
145
+ return Array.isArray(include);
146
+ }
138
147
  function selectToWire(value, property) {
139
148
  if (property?.type !== "select") {
140
149
  return value;
@@ -53,8 +53,10 @@ export interface OrderBy<Field extends string = string> {
53
53
  export interface OntologyQuery<Row = JsonRecord> {
54
54
  readonly where?: Where;
55
55
  readonly orderBy?: ReadonlyArray<OrderBy<keyof Row & string>>;
56
- /** Related records to add to each record, by relationship name. */
57
- readonly include?: {
56
+ /**
57
+ * Related records to add to each record, by relationship name: `["owner"]` or `{ owner: true }`.
58
+ */
59
+ readonly include?: ReadonlyArray<string> | {
58
60
  readonly [relationship: string]: true;
59
61
  };
60
62
  /** The `nextCursor` of the previous page. */
package/dist/ontology.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { SegmentStreamApiError, apiErrorFrom, readJson } from "./errors.js";
2
- import { actionInputToWire, encodeWhere, editsFromWire, queryToWire, recordFromWire, responseFromWire, } from "./ontology-wire.js";
2
+ import { actionInputToWire, encodeWhere, editsFromWire, includeToWire, queryToWire, recordFromWire, responseFromWire, } from "./ontology-wire.js";
3
3
  import { toCamelCase, toReversibleCamelCase, toSnakeCase } from "./ontology-names.js";
4
4
  const ENTITY_NAME = /^[a-z][a-zA-Z0-9]*(?:_[a-z0-9]+)*$/;
5
5
  const ACTION_NAME = ENTITY_NAME;
@@ -198,9 +198,11 @@ export function findParameters(query) {
198
198
  .join(","));
199
199
  }
200
200
  if (query.include !== undefined) {
201
- const relationships = Object.keys(query.include).filter((name) => query.include?.[name] === true);
201
+ const relationships = Object.entries(includeToWire(query.include))
202
+ .filter(([, included]) => included === true)
203
+ .map(([name]) => name);
202
204
  if (relationships.length > 0) {
203
- search.set("include", relationships.map(toSnakeCase).join(","));
205
+ search.set("include", relationships.join(","));
204
206
  }
205
207
  }
206
208
  if (query.after !== undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segmentstream-cloud/app",
3
- "version": "0.13.1",
3
+ "version": "0.13.2",
4
4
  "description": "Sign-in, users, permissions, the ontology client and warehouse data access for SegmentStream workspace apps built with Next.js.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "SegmentStream",