@nkzw/fate 0.0.3 → 0.0.4

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
@@ -1042,4 +1042,6 @@ Probably. One day. _Maybe._
1042
1042
  ## Acknowledgements
1043
1043
 
1044
1044
  - [Relay](https://relay.dev/), [Isograph](https://isograph.dev/) & [GraphQL](https://graphql.org/) for inspiration
1045
- - [Ricky Hanlon](https://x.com/rickyfm) for guidance on Async React
1045
+ - [Ricky Hanlon](https://x.com/rickyfm) for guidance on Async React
1046
+
1047
+ **_fate_** was created by [@cnakazawa](https://x.com/cnakazawa) and is maintained by [Nakazawa Tech](https://nakazawa.tech/).
package/lib/cli.mjs CHANGED
@@ -9,7 +9,7 @@ const isDataViewField = (field) => Boolean(field) && typeof field === "object" &
9
9
  * Builds the schema object used by the CLI generator from your data views and
10
10
  * list resolver configs.
11
11
  */
12
- const createFateSchema = (dataViews, lists) => {
12
+ const createSchema = (dataViews, lists) => {
13
13
  const canonicalViews = /* @__PURE__ */ new Map();
14
14
  const entities = {};
15
15
  const fateTypes = /* @__PURE__ */ new Map();
@@ -37,6 +37,7 @@ const createFateSchema = (dataViews, lists) => {
37
37
  if (!typeName) throw new Error("Data view is missing a type name.");
38
38
  if (!canonicalViews.has(typeName)) canonicalViews.set(typeName, view);
39
39
  entities[typeName.toLowerCase()] = { type: typeName };
40
+ ensureType(view);
40
41
  }
41
42
  for (const [name, list] of Object.entries(lists)) {
42
43
  const config = "fields" in list ? { view: list } : list;
@@ -88,8 +89,8 @@ const formatTypes = (types) => {
88
89
  const indentBlock = (value, spaces) => value.split("\n").map((line) => line.length ? `${" ".repeat(spaces)}${line}` : line).join("\n");
89
90
  const generate = async () => {
90
91
  console.log(styleText("bold", `Generating fate client…\n`));
91
- const [{ appRouter, Lists, ...dataViews }] = await Promise.all([import(moduleName)]);
92
- const { entities, types } = createFateSchema(Object.values(dataViews), Lists);
92
+ const { appRouter, Lists, ...dataViews } = await import(moduleName);
93
+ const { entities, types } = createSchema(Object.values(dataViews), Lists);
93
94
  const routerRecord = appRouter._def?.record ?? {};
94
95
  const mutationEntries = [];
95
96
  const byIdEntries = [];
package/lib/index.d.mts CHANGED
@@ -26,8 +26,8 @@ declare const __FateMutationResultBrand: unique symbol;
26
26
  type __ViewEntityAnchor<T$1 extends Entity> = {
27
27
  readonly [__FateEntityBrand]?: T$1;
28
28
  };
29
- type __ViewSelectionAnchor<S$1> = {
30
- [__FateSelectionBrand]?: S$1;
29
+ type __ViewSelectionAnchor<S> = {
30
+ [__FateSelectionBrand]?: S;
31
31
  };
32
32
  type __MutationEntityAnchor<T$1 extends Entity> = {
33
33
  readonly [__FateMutationEntityBrand]?: T$1;
@@ -126,33 +126,33 @@ type SelectionViewSpread<T$1 extends Entity> = { readonly [K in ViewTag]?: Reado
126
126
  /** Declarative selection of the fields a view needs from an entity. */
127
127
  type Selection<T$1 extends Entity> = SelectionShape<T$1> & SelectionViewSpread<T$1>;
128
128
  /** View payload stored on a view tag containing the raw selection used to mask data. */
129
- type ViewPayload<T$1 extends Entity, S$1 extends Selection<T$1> = Selection<T$1>> = Readonly<{
130
- select: S$1;
129
+ type ViewPayload<T$1 extends Entity, S extends Selection<T$1> = Selection<T$1>> = Readonly<{
130
+ select: S;
131
131
  [ViewKind]: true;
132
132
  }>;
133
133
  /** Definition of a view over an entity type, including the selection of fields. */
134
- type View<T$1 extends Entity, S$1 extends Selection<T$1> = Selection<T$1>> = Readonly<{
135
- [viewTag: ViewTag]: ViewPayload<T$1, S$1>;
136
- }> & __ViewEntityAnchor<T$1> & __ViewSelectionAnchor<S$1>;
137
- type HasViewTag<S$1> = S$1 extends { [K in ViewTag]?: infer P } ? P extends {
134
+ type View<T$1 extends Entity, S extends Selection<T$1> = Selection<T$1>> = Readonly<{
135
+ [viewTag: ViewTag]: ViewPayload<T$1, S>;
136
+ }> & __ViewEntityAnchor<T$1> & __ViewSelectionAnchor<S>;
137
+ type HasViewTag<S> = S extends { [K in ViewTag]?: infer P } ? P extends {
138
138
  [ViewKind]: true;
139
139
  } ? true : false : false;
140
140
  /**
141
141
  * Data returned from a resolved view with masking applied and view tags
142
142
  * attached for downstream composition.
143
143
  */
144
- type ViewData<T$1 extends Entity, S$1 extends Selection<T$1>> = Readonly<(S$1 extends Selection<T$1> ? Mask<T$1, S$1> : T$1) & {
144
+ type ViewData<T$1 extends Entity, S extends Selection<T$1>> = Readonly<(S extends Selection<T$1> ? Mask<T$1, S> : T$1) & {
145
145
  [ViewsTag]: Set<string>;
146
146
  }>;
147
147
  /**
148
148
  * Snapshot returned by the cache for a view, including the masked data and all
149
149
  * referenced entity IDs.
150
150
  */
151
- type ViewSnapshot<T$1 extends Entity, S$1 extends Selection<T$1>> = Readonly<{
151
+ type ViewSnapshot<T$1 extends Entity, S extends Selection<T$1>> = Readonly<{
152
152
  coverage: ReadonlyArray<readonly [id: EntityId, paths: ReadonlySet<string>]>;
153
- data: ViewData<T$1, S$1>;
153
+ data: ViewData<T$1, S>;
154
154
  }>;
155
- type ConnectionMask<T$1 extends Entity, S$1> = S$1 extends {
155
+ type ConnectionMask<T$1 extends Entity, S> = S extends {
156
156
  items: infer ItemSelection;
157
157
  pagination?: infer PaginationSelection;
158
158
  } ? {
@@ -173,7 +173,7 @@ type EntityName<T$1> = T$1 extends {
173
173
  __typename: infer N extends string;
174
174
  } ? N : never;
175
175
  /** Recursively applies a view selection to an entity to mask fields that aren't selected. */
176
- type Mask<T$1, S$1> = T$1 extends Array<infer U extends Entity> ? S$1 extends true ? Array<U> : S$1 extends ConnectionSelection<U> ? ConnectionMask<U, S$1> : HasViewTag<S$1> extends true ? Array<ViewRef<U['__typename']>> : Array<Mask<U, S$1>> : S$1 extends true ? T$1 : S$1 extends object ? HasViewTag<S$1> extends true ? ViewRef<EntityName<NonNullable<T$1>>> : { [K in keyof S$1 as K extends 'args' ? never : K]: S$1[K] extends true ? NonNullable<T$1>[Extract<K, keyof T$1>] : Mask<NonNullable<T$1>[Extract<K, keyof T$1>], Extract<S$1[K], object>> } & (T$1 extends Entity ? Pick<NonNullable<T$1>, '__typename'> : Record<never, never>) : T$1;
176
+ type Mask<T$1, S> = T$1 extends Array<infer U extends Entity> ? S extends true ? Array<U> : S extends ConnectionSelection<U> ? ConnectionMask<U, S> : HasViewTag<S> extends true ? Array<ViewRef<U['__typename']>> : Array<Mask<U, S>> : S extends true ? T$1 : S extends object ? HasViewTag<S> extends true ? ViewRef<EntityName<NonNullable<T$1>>> : { [K in keyof S as K extends 'args' ? never : K]: S[K] extends true ? NonNullable<T$1>[Extract<K, keyof T$1>] : Mask<NonNullable<T$1>[Extract<K, keyof T$1>], Extract<S[K], object>> } & (T$1 extends Entity ? Pick<NonNullable<T$1>, '__typename'> : Record<never, never>) : T$1;
177
177
  /** Entity type captured from a view definition. */
178
178
  type ViewEntity<V> = V extends View<infer T, any> ? T : never;
179
179
  /** Name of the entity type captured from a view definition. */
@@ -345,15 +345,15 @@ type SelectionPlan = {
345
345
  * Flattens a view into a `SelectionPlan`, expanding composed views and
346
346
  * partitioning nested args so the client can fetch exactly what is declared.
347
347
  */
348
- declare const getSelectionPlan: <T$1 extends Entity, S$1 extends Selection<T$1>, V extends View<T$1, S$1>>(viewComposition: V, ref: ViewRef<T$1["__typename"]> | null) => SelectionPlan;
348
+ declare const getSelectionPlan: <T$1 extends Entity, S extends Selection<T$1>, V extends View<T$1, S>>(viewComposition: V, ref: ViewRef<T$1["__typename"]> | null) => SelectionPlan;
349
349
  //#endregion
350
350
  //#region src/cache.d.ts
351
351
  declare class ViewDataCache {
352
352
  private cache;
353
353
  private rootDependencies;
354
354
  private dependencyIndex;
355
- get<T$1 extends Entity, S$1 extends Selection<T$1>, V extends View<T$1, S$1>>(entityId: EntityId, view: V, ref: ViewRef<T$1['__typename']>): FateThenable<ViewSnapshot<T$1, S$1>> | null;
356
- set<T$1 extends Entity, S$1 extends Selection<T$1>, V extends View<T$1, S$1>>(entityId: EntityId, view: V, ref: ViewRef<T$1['__typename']>, thenable: FateThenable<ViewSnapshot<T$1, S$1>>, dependencies: ReadonlySet<EntityId>): void;
355
+ get<T$1 extends Entity, S extends Selection<T$1>, V extends View<T$1, S>>(entityId: EntityId, view: V, ref: ViewRef<T$1['__typename']>): FateThenable<ViewSnapshot<T$1, S>> | null;
356
+ set<T$1 extends Entity, S extends Selection<T$1>, V extends View<T$1, S>>(entityId: EntityId, view: V, ref: ViewRef<T$1['__typename']>, thenable: FateThenable<ViewSnapshot<T$1, S>>, dependencies: ReadonlySet<EntityId>): void;
357
357
  invalidate(entityId: EntityId): void;
358
358
  private invalidateDependents;
359
359
  private delete;
@@ -528,7 +528,7 @@ declare class FateClient<Mutations extends Record<string, MutationDefinition<any
528
528
  id: string | number;
529
529
  [ViewsTag]: Set<string>;
530
530
  }>;
531
- readView<T$1 extends Entity, S$1 extends Selection<T$1>, V extends View<T$1, S$1>>(view: V, ref: ViewRef<T$1['__typename']>): FateThenable<ViewSnapshot<T$1, S$1>>;
531
+ readView<T$1 extends Entity, S extends Selection<T$1>, V extends View<T$1, S>>(view: V, ref: ViewRef<T$1['__typename']>): FateThenable<ViewSnapshot<T$1, S>>;
532
532
  private mergeListState;
533
533
  registerOptimisticUpdate(entityId: EntityId | null, select: ReadonlySet<string>): number | null;
534
534
  clearOptimisticUpdate(token: number | null): void;
@@ -570,7 +570,7 @@ declare function createClient<Mutations extends Record<string, MutationDefinitio
570
570
  declare const toEntityId: (type: TypeName, rawId: string | number) => EntityId;
571
571
  //#endregion
572
572
  //#region src/view.d.ts
573
- type SelectionValidation<T$1 extends Entity, S$1 extends Selection<T$1>> = Exclude<keyof Omit<S$1, typeof __FateEntityBrand | typeof __FateSelectionBrand>, keyof Selection<T$1>> extends never ? unknown : never;
573
+ type SelectionValidation<T$1 extends Entity, S extends Selection<T$1>> = Exclude<keyof Omit<S, typeof __FateEntityBrand | typeof __FateSelectionBrand>, keyof Selection<T$1>> extends never ? unknown : never;
574
574
  /**
575
575
  * Creates a reusable view for an object using the declared selection.
576
576
  *
@@ -580,6 +580,6 @@ type SelectionValidation<T$1 extends Entity, S$1 extends Selection<T$1>> = Exclu
580
580
  * title: true,
581
581
  * });
582
582
  */
583
- declare function view<T$1 extends Entity>(): <S$1 extends Selection<T$1>>(select: S$1 & SelectionValidation<T$1, S$1>) => View<T$1, S$1>;
583
+ declare function view<T$1 extends Entity>(): <S extends Selection<T$1>>(select: S & SelectionValidation<T$1, S>) => View<T$1, S>;
584
584
  //#endregion
585
585
  export { type ConnectionMetadata, type ConnectionRef, ConnectionTag, type Entity, type EntityId, FateClient, type AnyRecord as FateRecord, type ListItem, type Mask, type MutationDefinition, type MutationEntity, type MutationIdentifier, type MutationInput, type MutationResult, type NodesItem, type Pagination, type Request, type RequestMode, type RequestOptions, type RequestResult, type Selection, type Snapshot, type Transport, type TypeConfig, type View, type ViewData, type ViewEntity, type ViewEntityName, type ViewRef, type ViewSelection, type ViewSnapshot, type ViewTag, createClient, createTRPCTransport, getSelectionPlan, isViewTag, mutation, toEntityId, view };
package/lib/server.d.mts CHANGED
@@ -51,8 +51,8 @@ type DataViewConfig<Item$1 extends AnyRecord, Context> = Record<string, DataFiel
51
51
  * title: true,
52
52
  * });
53
53
  */
54
- declare function dataView<Item$1 extends AnyRecord, Context = unknown>(typeName?: string): <Fields$1 extends DataViewConfig<Item$1, Context>>(fields: Fields$1) => DataView<Item$1, Context> & {
55
- readonly [dataViewFieldsKey]: Fields$1;
54
+ declare function dataView<Item$1 extends AnyRecord, Context = unknown>(typeName?: string): <Fields extends DataViewConfig<Item$1, Context>>(fields: Fields) => DataView<Item$1, Context> & {
55
+ readonly [dataViewFieldsKey]: Fields;
56
56
  };
57
57
  /**
58
58
  * Marks a data view as a list resolver so the server can respond with
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nkzw/fate",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "fate is a modern data client for React.",
5
5
  "homepage": "https://github.com/nkzw-tech/fate",
6
6
  "repository": {