Skip to content

Commit

Permalink
Move objectset into client.api (#408)
Browse files Browse the repository at this point in the history
* refactor objectset

* fix import issue

* reorganize index file

* Add change to prevent semantic merge conflict with my pr

* add changest

---------

Co-authored-by: Eric Anderson <[email protected]>
  • Loading branch information
ssanjay1 and ericanderson authored Jun 21, 2024
1 parent a2cd534 commit 5e9d7d2
Show file tree
Hide file tree
Showing 46 changed files with 171 additions and 115 deletions.
6 changes: 6 additions & 0 deletions .changeset/tame-wolves-juggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@osdk/client.api": minor
"@osdk/client": minor
---

Refactored packages to move types over to client.api
1 change: 1 addition & 0 deletions examples-extra/basic/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"dependencies": {
"@osdk/api": "workspace:^",
"@osdk/client": "workspace:^",
"@osdk/client.api": "workspace:*",
"@osdk/examples.basic.sdk": "workspace:^",
"@osdk/foundry": "workspace:^",
"@osdk/internal.foundry": "workspace:^",
Expand Down
2 changes: 1 addition & 1 deletion examples-extra/basic/cli/src/demoStrictness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import type { Osdk } from "@osdk/client";
import type { Osdk } from "@osdk/client.api";
import {
BoundariesUsState,
Employee,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* limitations under the License.
*/

import type { Client, Osdk } from "@osdk/client";
import type { Client } from "@osdk/client";
import type { Osdk } from "@osdk/client.api";
import { Employee } from "@osdk/examples.basic.sdk";
import { expectType } from "ts-expect";

Expand Down
2 changes: 1 addition & 1 deletion examples-extra/basic/cli/src/runInterfacesTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import type { Osdk, PageResult } from "@osdk/client";
import type { Osdk, PageResult } from "@osdk/client.api";
import { Employee, FooInterface } from "@osdk/examples.basic.sdk";
import invariant from "tiny-invariant";
import type { TypeOf } from "ts-expect";
Expand Down
3 changes: 2 additions & 1 deletion examples-extra/basic/cli/src/typeChecks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
* limitations under the License.
*/

import type { Client, ObjectSet, Osdk, PageResult } from "@osdk/client";
import type { Client } from "@osdk/client";
import type { ObjectSet, Osdk, PageResult } from "@osdk/client.api";
import type { Employee } from "@osdk/examples.basic.sdk";
import { Ontology } from "@osdk/examples.basic.sdk";
import type { TypeOf } from "ts-expect";
Expand Down
49 changes: 24 additions & 25 deletions examples-extra/todoapp/src/useTodos.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { ActionValidationError, type Osdk } from "@osdk/client";
import type { ObjectTypeDefinition } from "@osdk/api";
import { ActionValidationError } from "@osdk/client";
import type { Osdk } from "@osdk/client.api";
import { useCallback, useEffect } from "react";
import type { KeyedMutator } from "swr";
import useSWR from "swr";
import { $ } from "./foundryClient";
import * as MyOsdk from "./generatedNoCheck2";
import type { ObjectTypeDefinition } from "@osdk/api";

declare global {
interface ArrayConstructor {
Expand All @@ -16,7 +17,7 @@ declare global {
iterableOrArrayLike:
| AsyncIterable<T>
| Iterable<T | PromiseLike<T>>
| ArrayLike<T | PromiseLike<T>>
| ArrayLike<T | PromiseLike<T>>,
): Promise<T[]>;

/**
Expand All @@ -30,7 +31,7 @@ declare global {
fromAsync<T, U>(
iterableOrArrayLike: AsyncIterable<T> | Iterable<T> | ArrayLike<T>,
mapFn: (value: Awaited<T>) => U,
thisArg?: any
thisArg?: any,
): Promise<Awaited<U>[]>;
}
}
Expand All @@ -39,11 +40,11 @@ export function useTodos() {
const { data, isLoading, error, isValidating, mutate } = useSWR(
"/todos",
async () => await Array.fromAsync<SimpleTodo>($(MyOsdk.Todo).asyncIter()),
{ keepPreviousData: true, revalidateOnFocus: false }
{ keepPreviousData: true, revalidateOnFocus: false },
);

const toggleComplete = useCallback(
async function (todo: SimpleTodo) {
async function(todo: SimpleTodo) {
const b = !todo.isComplete;
await mutate(
async () => {
Expand All @@ -57,10 +58,10 @@ export function useTodos() {
{
optimisticData: updateTodo.bind(undefined, todo.id!, b),
rollbackOnError: true,
}
},
);
},
[mutate]
[mutate],
);

const createTodoMutator = useCallback(
Expand All @@ -87,7 +88,7 @@ export function useTodos() {
if (constraint.type === "stringLength") {
if (constraint.gte != null && constraint.lte != null) {
setError?.(
`Todo must be between ${constraint.gte}-${constraint.lte} characters`
`Todo must be between ${constraint.gte}-${constraint.lte} characters`,
);
}
}
Expand All @@ -105,11 +106,11 @@ export function useTodos() {
optimisticData: (todos = []) => [...todos, createFauxTodo(title)],
rollbackOnError: true,
throwOnError: true,
}
},
);
return undefined;
},
[mutate]
[mutate],
);

return {
Expand All @@ -122,7 +123,6 @@ export function useTodos() {
};
}


type OsdkPropsOnly<T extends ObjectTypeDefinition<any>> = Omit<
Osdk<T>,
"$as" | "$link"
Expand All @@ -146,15 +146,15 @@ function createFauxTodo(title: string): SimpleTodo {
function updateTodo(
id: string,
isComplete: boolean,
todos: SimpleTodo[] | undefined
todos: SimpleTodo[] | undefined,
): SimpleTodo[] {
return updateOne(todos, id, (todo) => ({ ...todo, isComplete })) ?? [];
}

function updateOne<T extends { __primaryKey: Q }, Q>(
things: T[] | undefined,
primaryKey: Q,
update: (thing: T) => T
update: (thing: T) => T,
) {
return things?.map((thing) => {
if (thing.__primaryKey === primaryKey) {
Expand Down Expand Up @@ -182,15 +182,15 @@ export function useSubscribe(mutate: KeyedMutator<SimpleTodo[]>) {
} else {
byApiNameByPK.set(
object.$apiName,
new Map([[object.$primaryKey, object]])
new Map([[object.$primaryKey, object]]),
);
}
}

// get the new version of an object that has changed, removing it from the list of updates
const getUpdate = (
apiName: (typeof objects)[0]["$apiName"],
primaryKey: (typeof objects)[0]["$primaryKey"]
primaryKey: (typeof objects)[0]["$primaryKey"],
) => {
const byPk = byApiNameByPK.get(apiName);
if (byPk) {
Expand All @@ -204,14 +204,13 @@ export function useSubscribe(mutate: KeyedMutator<SimpleTodo[]>) {

mutate((data) => {
// update any Todos that we got a new version for
const updated =
data?.map((object) => {
const updateObject = getUpdate(
object.$apiName,
object.$primaryKey
);
return updateObject ?? object;
}) ?? [];
const updated = data?.map((object) => {
const updateObject = getUpdate(
object.$apiName,
object.$primaryKey,
);
return updateObject ?? object;
}) ?? [];

// add any new Todos to the bottom
for (const byPk of byApiNameByPK.values()) {
Expand All @@ -235,6 +234,6 @@ export function useSubscribe(mutate: KeyedMutator<SimpleTodo[]>) {

return function() {
unsubscribe();
}
};
}, [mutate]);
}
3 changes: 3 additions & 0 deletions packages/client.api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"transpile": "tsup",
"typecheck": "../../scripts/build_common/typecheck.sh esm"
},
"dependencies": {
"@osdk/api": "workspace:^"
},
"peerDependencies": {
"@osdk/api": "workspace:^",
"@osdk/internal.foundry": "workspace:^",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ import type {
ObjectOrInterfaceDefinition,
ObjectTypeDefinition,
} from "@osdk/api";
import type {
OsdkBase,
OsdkObjectPrimaryKeyType,
OsdkObjectPropertyType,
} from "@osdk/client.api";
import type { OsdkObjectPropertyType } from "./Definitions.js";
import type { OsdkObjectLinksObject } from "./definitions/LinkDefinitions.js";
import type { UnionIfTrue } from "./object/FetchPageResult.js";
import type { OsdkBase } from "./OsdkBase.js";
import type { OsdkObjectPrimaryKeyType } from "./OsdkObjectPrimaryKeyType.js";

type DropDollarOptions<T extends string> = Exclude<
T,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/client.api/src/aggregate/AggregatableKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import type { ObjectOrInterfaceDefinition } from "@osdk/api";
import type { PropertyValueClientToWire } from "@osdk/client.api";
import type { PropertyValueClientToWire } from "../mapping/PropertyValueMapping.js";

export type StringAggregateOption = "approximateDistinct";
export type NumericAggregateOption =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import type {
ObjectTypeLinkDefinition,
ObjectTypeLinkKeysFrom2,
} from "@osdk/api";
import type { Result } from "@osdk/client.api";
import type { SelectArg, SelectArgToKeys } from "../object/FetchPageArgs.js";
import type { Result } from "../object/Result.js";
import type { ObjectSet } from "../objectSet/ObjectSet.js";
import type { Osdk } from "../OsdkObjectFrom.js";

Expand Down
43 changes: 40 additions & 3 deletions packages/client.api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export type {
UnorderedAggregationClause,
} from "./aggregate/AggregationsClause.js";
export type { AggregationsResults } from "./aggregate/AggregationsResults.js";
export { DistanceUnitMapping } from "./aggregate/WhereClause.js";
export type {
AndWhereClause,
GeoFilter,
Expand All @@ -50,14 +51,19 @@ export type {
PossibleWhereClauseFilters,
WhereClause,
} from "./aggregate/WhereClause.js";
export { DistanceUnitMapping } from "./aggregate/WhereClause.js";
export type { OsdkObjectPropertyType } from "./Definitions.js";
export type {
DefaultToFalse,
OsdkObjectLinksEntry,
OsdkObjectLinksObject,
SingleLinkAccessor,
} from "./definitions/LinkDefinitions.js";
export { DurationMapping } from "./groupby/GroupByClause.js";
export type {
AllGroupByValues,
GroupByClause,
GroupByRange,
} from "./groupby/GroupByClause.js";
export { DurationMapping } from "./groupby/GroupByClause.js";
export type {
PropertyValueClientToWire,
PropertyValueWireToClient,
Expand All @@ -67,11 +73,42 @@ export type {
AttachmentMetadata,
AttachmentUpload,
} from "./object/Attachment.js";
export type { Result } from "./object/Result.js";
export type {
Augment,
Augments,
FetchInterfacePageArgs,
FetchPageArgs,
NullabilityAdherence,
NullabilityAdherenceDefault,
OrderByArg,
SelectArg,
SelectArgToKeys,
} from "./object/FetchPageArgs.js";
export type {
FetchPageResult,
RespectNullability,
SingleOsdkResult,
UnionIfFalse,
UnionIfTrue,
} from "./object/FetchPageResult.js";
export { isOk } from "./object/Result.js";
export type { Result } from "./object/Result.js";
export type { BaseObjectSet } from "./objectSet/BaseObjectSet.js";
export type {
InterfaceObjectSet,
MinimalObjectSet,
ObjectSet,
} from "./objectSet/ObjectSet.js";
export type { OsdkBase } from "./OsdkBase.js";
export type { OsdkObject } from "./OsdkObject.js";
export type {
ConvertProps,
Osdk,
OsdkObjectOrInterfaceFrom,
ValidToFrom,
} from "./OsdkObjectFrom.js";
export type { OsdkObjectPrimaryKeyType } from "./OsdkObjectPrimaryKeyType.js";
export type { PageResult } from "./PageResult.js";
export type { LinkedType, LinkNames } from "./util/LinkUtils.js";
export type { NOOP } from "./util/NOOP.js";

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,11 @@ import type {
ObjectOrInterfacePropertyKeysFrom2,
ObjectTypeDefinition,
} from "@osdk/api";
import type {
AggregateOpts,
AggregateOptsThatErrorsAndDisallowsOrderingWithMultipleGroupBy,
AggregationsResults,
BaseObjectSet,
LinkedType,
LinkNames,
PropertyValueClientToWire,
Result,
WhereClause,
} from "@osdk/client.api";
import type { AggregateOpts } from "../aggregate/AggregateOpts.js";
import type { AggregateOptsThatErrorsAndDisallowsOrderingWithMultipleGroupBy } from "../aggregate/AggregateOptsThatErrors.js";
import type { AggregationsResults } from "../aggregate/AggregationsResults.js";
import type { WhereClause } from "../aggregate/WhereClause.js";
import type { PropertyValueClientToWire } from "../mapping/PropertyValueMapping.js";
import type {
Augments,
FetchPageArgs,
Expand All @@ -42,7 +36,10 @@ import type {
FetchPageResult,
SingleOsdkResult,
} from "../object/FetchPageResult.js";
import type { Result } from "../object/Result.js";
import type { Osdk } from "../OsdkObjectFrom.js";
import type { LinkedType, LinkNames } from "../util/LinkUtils.js";
import type { BaseObjectSet } from "./BaseObjectSet.js";

export interface MinimalObjectSet<Q extends ObjectOrInterfaceDefinition>
extends BaseObjectSet<Q>
Expand Down
3 changes: 1 addition & 2 deletions packages/client/src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ import type {
ObjectTypeDefinition,
VersionBound,
} from "@osdk/api";
import type { ActionSignatureFromDef } from "@osdk/client.api";
import type { ActionSignatureFromDef, ObjectSet } from "@osdk/client.api";
import type { SharedClient } from "@osdk/shared.client";
import type { MinimalClient } from "./MinimalClientContext.js";
import type { ObjectSet } from "./objectSet/ObjectSet.js";
import type { SatisfiesSemver } from "./SatisfiesSemver.js";

export type CheckVersionBound<Q> = Q extends VersionBound<infer V> ? (
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/ObjectSetCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import type {
ObjectOrInterfaceKeysFrom,
OntologyDefinition,
} from "@osdk/api";
import type { ObjectSet } from "@osdk/client.api";
import type { Client } from "./Client.js";
import type { ObjectSet } from "./objectSet/ObjectSet.js";

/**
* A type that creates an object set for each object in the ontology.
Expand Down
Loading

0 comments on commit 5e9d7d2

Please sign in to comment.