Skip to content

Commit

Permalink
Merge pull request #3 from koordinates/beta
Browse files Browse the repository at this point in the history
  • Loading branch information
UberMouse authored Aug 4, 2022
2 parents f2a6931 + 86640c7 commit 3589beb
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 30 deletions.
8 changes: 8 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
The MIT License (MIT)
Copyright © 2022 Koordinates

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@ export {
type LinkProps,
type AnyRoute,
type RouteParams,
type RouteArguments,
type Route,
type RouteMeta,
type Routing404Event,
type StyledLink,
type ArgumentsForRoute,
type Options,
type Params,
type Query,
type Meta,
type SharedMeta,
type RouteArgumentFunctions,
buildCreateRoute,
matchRoute,
} from "./routing";
Expand Down
35 changes: 30 additions & 5 deletions src/routing/createRoute/createRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ type EmptyKeys<T> = keyof {
type MakeEmptyObjectPropertiesOptional<T> = Omit<T, EmptyKeys<T>> &
Partial<Pick<T, EmptyKeys<T>>>;

/**
* @public
*/
export type RouteArguments<TParams, TQuery, TMeta> = TParams extends undefined
? TQuery extends undefined
? TMeta extends undefined
Expand Down Expand Up @@ -50,6 +53,9 @@ type EmptyRouteArguments<TParams, TQuery> = IsEmptyObject<
: false
: false;

/**
* @public
*/
export type RouteArgumentFunctions<
TReturn,
TParams,
Expand Down Expand Up @@ -145,7 +151,10 @@ export type AnyRoute = {
querySchema?: Z.ZodObject<any>;
};

type Options<
/**
* @public
*/
export type Options<
TParamsSchema extends Z.ZodObject<any>,
TQuerySchema extends Z.ZodObject<any>,
TMetaSchema
Expand All @@ -155,7 +164,10 @@ type Options<
meta?: TMetaSchema;
};

type SharedMeta = {
/**
* @public
*/
export type SharedMeta = {
/**
* Suppresses this routing change event from being picked up by react-router
*/
Expand All @@ -170,9 +182,22 @@ type SharedMeta = {
replace?: boolean;
};

type Params<T> = T extends { params: infer TParams } ? TParams : undefined;
type Query<T> = T extends { query: infer TQuery } ? TQuery : undefined;
type Meta<T> = T extends { meta: infer TMeta } ? TMeta : undefined;
/**
* @public
*/
export type Params<T> = T extends { params: infer TParams }
? TParams
: undefined;

/**
* @public
*/
export type Query<T> = T extends { query: infer TQuery } ? TQuery : undefined;

/**
* @public
*/
export type Meta<T> = T extends { meta: infer TMeta } ? TMeta : undefined;

/**
* @public
Expand Down
6 changes: 6 additions & 0 deletions src/routing/createRoute/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ export {
type RouteParams,
type RouteMeta,
type ArgumentsForRoute,
type Options,
type Params,
type Query,
type Meta,
type SharedMeta,
type RouteArgumentFunctions,
} from "./createRoute";
7 changes: 7 additions & 0 deletions src/routing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ export {
type AnyRoute,
type RouteParams,
type RouteMeta,
type RouteArguments,
type ArgumentsForRoute,
type Options,
type Params,
type Query,
type Meta,
type SharedMeta,
type RouteArgumentFunctions,
buildCreateRoute,
} from "./createRoute";
export { joinRoutes } from "./joinRoutes";
Expand Down
17 changes: 13 additions & 4 deletions src/slots/slots.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
enum SlotType {
/**
* @public
*/
export enum SlotType {
SingleSlot,
MultiSlot,
}

type SingleSlot<T> = {
/**
* @public
*/
export type SingleSlot<T> = {
type: SlotType.SingleSlot;
name: T;
getId(): string;
};

type MultiSlot<T> = {
/**
* @public
*/
export type MultiSlot<T> = {
type: SlotType.MultiSlot;
name: T;
getId(id: string): string;
Expand Down Expand Up @@ -43,7 +52,7 @@ export function multiSlot<T extends string>(name: T): MultiSlot<T> {
}

/**
* @internal
* @public
*/
export type GetSlotNames<TSlots extends readonly Slot[]> =
TSlots[number]["name"];
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"compilerOptions": {
"incremental": true,
"declaration": true,
"target": "ES2020",
"target": "ES2018",
"module": "ES2020",
"jsx": "react",
"strict": true,
Expand Down
104 changes: 84 additions & 20 deletions xstate-tree.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ export type AnyRoute = {
querySchema?: Z.ZodObject<any>;
};

// Warning: (ae-forgotten-export) The symbol "RouteArguments" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export type ArgumentsForRoute<T> = T extends Route<infer TParams, infer TQuery, any, infer TMeta> ? RouteArguments<TParams, TQuery, TMeta> : never;

Expand Down Expand Up @@ -136,9 +134,7 @@ export function buildXStateTreeMachine<TContext, TEvent extends EventObject, TTy
// @public (undocumented)
export const genericSlotsTestingDummy: any;

// Warning: (ae-internal-missing-underscore) The name "GetSlotNames" should be prefixed with an underscore because the declaration is marked as @internal
//
// @internal (undocumented)
// @public (undocumented)
export type GetSlotNames<TSlots extends readonly Slot[]> = TSlots[number]["name"];

// @public
Expand Down Expand Up @@ -182,21 +178,48 @@ export function loggingMetaOptions<TEvents extends EventObject, TContext>(ignore
// @public (undocumented)
export function matchRoute<TRoutes extends Route<any, any, any, any>[]>(routes: TRoutes, basePath: string, path: string, search: string): Return;

// Warning: (ae-forgotten-export) The symbol "MultiSlot" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export type Meta<T> = T extends {
meta: infer TMeta;
} ? TMeta : undefined;

// @public (undocumented)
export type MultiSlot<T> = {
type: SlotType.MultiSlot;
name: T;
getId(id: string): string;
};

// @public (undocumented)
export function multiSlot<T extends string>(name: T): MultiSlot<T>;

// @public (undocumented)
export function onBroadcast(handler: (event: GlobalEvents) => void): () => void;

// @public (undocumented)
export type Options<TParamsSchema extends Z.ZodObject<any>, TQuerySchema extends Z.ZodObject<any>, TMetaSchema> = {
params?: TParamsSchema;
query?: TQuerySchema;
meta?: TMetaSchema;
};

// @public (undocumented)
export type Params<T> = T extends {
params: infer TParams;
} ? TParams : undefined;

// @public
export type PickEvent<T extends Extract<GlobalEvents, {
type: string;
}>["type"]> = Extract<GlobalEvents, {
type: T;
}>;

// @public (undocumented)
export type Query<T> = T extends {
query: infer TQuery;
} ? TQuery : undefined;

// @public (undocumented)
export type Route<TParams, TQuery, TEvent, TMeta> = {
matches: (url: string, search: string) => ({
Expand All @@ -217,6 +240,38 @@ export type Route<TParams, TQuery, TEvent, TMeta> = {
querySchema?: Z.ZodObject<any>;
};

// Warning: (ae-forgotten-export) The symbol "IsEmptyObject" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "EmptyRouteArguments" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "MakeEmptyObjectPropertiesOptional" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export type RouteArgumentFunctions<TReturn, TParams, TQuery, TMeta, TArgs = RouteArguments<TParams, TQuery, TMeta>> = IsEmptyObject<TArgs> extends true ? () => TReturn : keyof TArgs extends "meta" ? (args?: TArgs) => TReturn : EmptyRouteArguments<TParams, TQuery> extends true ? (args?: Partial<TArgs>) => TReturn : (args: MakeEmptyObjectPropertiesOptional<TArgs>) => TReturn;

// @public (undocumented)
export type RouteArguments<TParams, TQuery, TMeta> = TParams extends undefined ? TQuery extends undefined ? TMeta extends undefined ? {} : {
meta?: TMeta;
} : TMeta extends undefined ? {
query: TQuery;
} : {
query: TQuery;
meta?: TMeta;
} : TQuery extends undefined ? TMeta extends undefined ? {
params: TParams;
} : {
params: TParams;
meta?: TMeta;
} : TMeta extends undefined ? {
params: TParams;
query: TQuery;
} : {
params: TParams;
query: TQuery;
meta?: TMeta;
};

// @public (undocumented)
export type RouteMeta<T> = T extends Route<any, any, any, infer TMeta> ? TMeta : undefined;

// @public (undocumented)
export type RouteParams<T> = T extends Route<infer TParams, any, any, any> ? TParams : undefined;

Expand All @@ -235,8 +290,20 @@ export type RoutingEvent<T> = T extends Route<infer TParams, infer TQuery, infer
meta: TMeta;
} : never;

// Warning: (ae-forgotten-export) The symbol "SingleSlot" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export type SharedMeta = {
doNotNotifyReactRouter?: boolean;
indexEvent?: boolean;
replace?: boolean;
};

// @public (undocumented)
export type SingleSlot<T> = {
type: SlotType.SingleSlot;
name: T;
getId(): string;
};

// @public (undocumented)
export function singleSlot<T extends string>(name: T): SingleSlot<T>;

Expand All @@ -255,6 +322,14 @@ context: unknown;
context: unknown;
}, any, any, any>;

// @public (undocumented)
export enum SlotType {
// (undocumented)
MultiSlot = 1,
// (undocumented)
SingleSlot = 0
}

// @public (undocumented)
export type StyledLink<TStyleProps = {}> = <TRoute extends AnyRoute>(props: LinkProps<TRoute> & TStyleProps) => JSX.Element;

Expand Down Expand Up @@ -286,17 +361,6 @@ export type XstateTreeMachineStateSchema<TContext, TEvent extends EventObject, T
meta: XStateTreeMachineMeta<TContext, TEvent, TTypestate, TSelectors, TActions, TInterpreter, TSlots>;
};

// Warnings were encountered during analysis:
//
// src/routing/createRoute/createRoute.ts:228:5 - (ae-forgotten-export) The symbol "Options" needs to be exported by the entry point index.d.ts
// src/routing/createRoute/createRoute.ts:228:5 - (ae-forgotten-export) The symbol "Params" needs to be exported by the entry point index.d.ts
// src/routing/createRoute/createRoute.ts:228:5 - (ae-forgotten-export) The symbol "Query" needs to be exported by the entry point index.d.ts
// src/routing/createRoute/createRoute.ts:228:5 - (ae-forgotten-export) The symbol "Meta" needs to be exported by the entry point index.d.ts
// src/routing/createRoute/createRoute.ts:228:5 - (ae-forgotten-export) The symbol "SharedMeta" needs to be exported by the entry point index.d.ts
// src/routing/createRoute/createRoute.ts:251:37 - (ae-forgotten-export) The symbol "RouteArgumentFunctions" needs to be exported by the entry point index.d.ts
// src/routing/createRoute/createRoute.ts:324:5 - (ae-forgotten-export) The symbol "RouteMeta" needs to be exported by the entry point index.d.ts
// src/types.ts:76:3 - (ae-incompatible-release-tags) The symbol "slots" is marked as @public, but its signature references "GetSlotNames" which is marked as @internal

// (No @packageDocumentation comment for this package)

```

0 comments on commit 3589beb

Please sign in to comment.