houdini-svelte 1.0.2 → 1.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.
@@ -1,4 +1,3 @@
1
- import type { DocumentStore } from '$houdini/runtime/client';
2
1
  import type { MutationArtifact, GraphQLObject, QueryResult } from '$houdini/runtime/lib/types';
3
2
  import type { RequestEvent } from '@sveltejs/kit';
4
3
  import { BaseStore } from './base';
@@ -9,7 +8,6 @@ export declare class MutationStore<_Data extends GraphQLObject, _Input extends {
9
8
  fetch?: typeof globalThis.fetch;
10
9
  event?: RequestEvent;
11
10
  } & MutationConfig<_Data, _Input, _Optimistic>): Promise<QueryResult<_Data, _Input>>;
12
- subscribe(...args: Parameters<DocumentStore<_Data, _Input>['subscribe']>): import("$houdini/runtime/lib").Unsubscriber;
13
11
  }
14
12
  export type MutationConfig<_Result, _Input, _Optimistic> = {
15
13
  optimisticResponse?: _Optimistic;
@@ -48,9 +48,6 @@ class MutationStore extends import_base.BaseStore {
48
48
  }
49
49
  });
50
50
  }
51
- subscribe(...args) {
52
- return this.observer.subscribe(...args);
53
- }
54
51
  }
55
52
  // Annotate the CommonJS export names for ESM import in node:
56
53
  0 && (module.exports = {
@@ -1,15 +1,12 @@
1
1
  import type { FetchContext } from '$houdini/runtime/client/plugins/fetch';
2
2
  import type { GraphQLObject, HoudiniFetchContext, MutationArtifact, QueryArtifact, QueryResult, CachePolicies } from '$houdini/runtime/lib/types';
3
3
  import type { LoadEvent, RequestEvent } from '@sveltejs/kit';
4
- import type { Readable } from 'svelte/store';
5
4
  import type { PluginArtifactData } from '../../plugin/artifactData';
6
5
  import { BaseStore } from './base';
7
6
  export declare class QueryStore<_Data extends GraphQLObject, _Input extends {}> extends BaseStore<_Data, _Input, QueryArtifact> {
8
- #private;
9
7
  variables: boolean;
10
8
  kind: "HoudiniQuery";
11
9
  protected loadPending: boolean;
12
- protected subscriberCount: number;
13
10
  protected storeName: string;
14
11
  constructor({ artifact, storeName, variables }: StoreConfig<_Data, _Input, QueryArtifact>);
15
12
  /**
@@ -19,8 +16,6 @@ export declare class QueryStore<_Data extends GraphQLObject, _Input extends {}>
19
16
  fetch(params?: LoadEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
20
17
  fetch(params?: ClientFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
21
18
  fetch(params?: QueryStoreFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
22
- get name(): string;
23
- subscribe(...args: Parameters<Readable<QueryResult<_Data, _Input>>['subscribe']>): () => void;
24
19
  }
25
20
  export type StoreConfig<_Data extends GraphQLObject, _Input, _Artifact> = {
26
21
  artifact: _Artifact & {
@@ -28,32 +28,27 @@ __export(query_exports, {
28
28
  fetchParams: () => fetchParams
29
29
  });
30
30
  module.exports = __toCommonJS(query_exports);
31
- var import_client = require("$houdini/runtime/client");
32
31
  var log = __toESM(require("$houdini/runtime/lib/log"), 1);
33
32
  var import_types = require("$houdini/runtime/lib/types");
34
33
  var import_store = require("svelte/store");
35
34
  var import_adapter = require("../adapter");
36
- var import_client2 = require("../client");
35
+ var import_client = require("../client");
37
36
  var import_session = require("../session");
38
37
  var import_base = require("./base");
39
38
  class QueryStore extends import_base.BaseStore {
40
39
  variables;
41
40
  kind = import_types.CompiledQueryKind;
42
41
  loadPending = false;
43
- subscriberCount = 0;
44
42
  storeName;
45
- #store;
46
- #unsubscribe = null;
47
43
  constructor({ artifact, storeName, variables }) {
48
44
  const fetching = artifact.pluginData?.["houdini-svelte"].isManualLoad !== true;
49
45
  super({ artifact, fetching });
50
46
  this.storeName = storeName;
51
47
  this.variables = variables;
52
- this.#store = new import_client.DocumentStore({ artifact, client: null, fetching });
53
48
  }
54
49
  async fetch(args) {
55
- await (0, import_client2.initClient)();
56
- await this.#setup(false);
50
+ await (0, import_client.initClient)();
51
+ this.setup();
57
52
  const { policy, params, context } = await fetchParams(this.artifact, this.storeName, args);
58
53
  if (!import_adapter.isBrowser && !(params && "fetch" in params) && (!params || !("event" in params))) {
59
54
  log.error(contextError(this.storeName));
@@ -101,46 +96,6 @@ This will result in duplicate queries. If you are trying to ensure there is alwa
101
96
  }
102
97
  return (0, import_store.get)(this.observer);
103
98
  }
104
- get name() {
105
- return this.artifact.name;
106
- }
107
- #setup(init = true) {
108
- let initPromise = Promise.resolve();
109
- try {
110
- (0, import_client2.getClient)();
111
- } catch {
112
- initPromise = (0, import_client2.initClient)();
113
- }
114
- initPromise.then(() => {
115
- if (this.#unsubscribe) {
116
- return;
117
- }
118
- this.#unsubscribe = this.observer.subscribe((value) => {
119
- this.#store.set(value);
120
- });
121
- if (init) {
122
- return this.observer.send({
123
- setup: true,
124
- variables: (0, import_store.get)(this.observer).variables
125
- });
126
- }
127
- });
128
- }
129
- subscribe(...args) {
130
- const bubbleUp = this.#store.subscribe(...args);
131
- if (import_adapter.isBrowser && (this.subscriberCount === 0 || !this.#unsubscribe)) {
132
- this.#setup();
133
- }
134
- this.subscriberCount = (this.subscriberCount ?? 0) + 1;
135
- return () => {
136
- this.subscriberCount--;
137
- if (this.subscriberCount <= 0) {
138
- this.#unsubscribe?.();
139
- this.#unsubscribe = null;
140
- bubbleUp();
141
- }
142
- };
143
- }
144
99
  }
145
100
  async function fetchParams(artifact, storeName, params) {
146
101
  let policy = params?.policy;
@@ -1,4 +1,3 @@
1
- import type { DocumentStore } from '$houdini/runtime/client';
2
1
  import type { SubscriptionArtifact } from '$houdini/runtime/lib/types';
3
2
  import type { GraphQLObject } from 'houdini';
4
3
  import { BaseStore } from './base';
@@ -7,8 +6,8 @@ export declare class SubscriptionStore<_Data extends GraphQLObject, _Input exten
7
6
  constructor({ artifact }: {
8
7
  artifact: SubscriptionArtifact;
9
8
  });
10
- subscribe(...args: Parameters<DocumentStore<_Data, _Input>['subscribe']>): import("$houdini/runtime/lib").Unsubscriber;
11
9
  listen(variables?: _Input, args?: {
12
10
  metadata: App.Metadata;
13
11
  }): Promise<void>;
12
+ unlisten(): Promise<void>;
14
13
  }
@@ -30,9 +30,6 @@ class SubscriptionStore extends import_base.BaseStore {
30
30
  constructor({ artifact }) {
31
31
  super({ artifact });
32
32
  }
33
- subscribe(...args) {
34
- return this.observer?.subscribe(...args);
35
- }
36
33
  async listen(variables, args) {
37
34
  await (0, import_client.initClient)();
38
35
  this.observer.send({
@@ -41,6 +38,10 @@ class SubscriptionStore extends import_base.BaseStore {
41
38
  metadata: args?.metadata
42
39
  });
43
40
  }
41
+ async unlisten() {
42
+ await (0, import_client.initClient)();
43
+ await this.observer.cleanup();
44
+ }
44
45
  }
45
46
  // Annotate the CommonJS export names for ESM import in node:
46
47
  0 && (module.exports = {
@@ -1,8 +1,12 @@
1
- import type { DocumentStore, ObserveParams } from '$houdini/runtime/client';
2
- import type { GraphQLObject, DocumentArtifact } from '$houdini/runtime/lib/types';
1
+ import { DocumentStore, type ObserveParams } from '$houdini/runtime/client';
2
+ import type { GraphQLObject, DocumentArtifact, QueryResult } from '$houdini/runtime/lib/types';
3
+ import type { Readable } from 'svelte/store';
3
4
  export declare class BaseStore<_Data extends GraphQLObject, _Input extends {}, _Artifact extends DocumentArtifact = DocumentArtifact> {
4
5
  #private;
5
- constructor(params: ObserveParams<_Data, _Artifact>);
6
6
  get artifact(): _Artifact;
7
+ get name(): string;
8
+ constructor(params: ObserveParams<_Data, _Artifact>);
7
9
  protected get observer(): DocumentStore<_Data, _Input>;
10
+ subscribe(...args: Parameters<Readable<QueryResult<_Data, _Input>>['subscribe']>): () => void;
11
+ setup(init?: boolean): void;
8
12
  }
@@ -1,12 +1,25 @@
1
- import { getClient } from "../client";
1
+ import { DocumentStore } from "$houdini/runtime/client";
2
+ import { get } from "svelte/store";
3
+ import { isBrowser } from "../adapter";
4
+ import { getClient, initClient } from "../client";
2
5
  class BaseStore {
3
6
  #params;
4
- constructor(params) {
5
- this.#params = params;
6
- }
7
7
  get artifact() {
8
8
  return this.#params.artifact;
9
9
  }
10
+ get name() {
11
+ return this.artifact.name;
12
+ }
13
+ #store;
14
+ #unsubscribe = null;
15
+ constructor(params) {
16
+ this.#store = new DocumentStore({
17
+ artifact: params.artifact,
18
+ client: null,
19
+ fetching: params.fetching
20
+ });
21
+ this.#params = params;
22
+ }
10
23
  #observer = null;
11
24
  get observer() {
12
25
  if (this.#observer) {
@@ -15,6 +28,44 @@ class BaseStore {
15
28
  this.#observer = getClient().observe(this.#params);
16
29
  return this.#observer;
17
30
  }
31
+ subscribe(...args) {
32
+ const bubbleUp = this.#store.subscribe(...args);
33
+ if (isBrowser && (this.#subscriberCount === 0 || !this.#unsubscribe)) {
34
+ this.setup();
35
+ }
36
+ this.#subscriberCount = (this.#subscriberCount ?? 0) + 1;
37
+ return () => {
38
+ this.#subscriberCount--;
39
+ if (this.#subscriberCount <= 0) {
40
+ this.#unsubscribe?.();
41
+ this.#unsubscribe = null;
42
+ bubbleUp();
43
+ }
44
+ };
45
+ }
46
+ #subscriberCount = 0;
47
+ setup(init = true) {
48
+ let initPromise = Promise.resolve();
49
+ try {
50
+ getClient();
51
+ } catch {
52
+ initPromise = initClient();
53
+ }
54
+ initPromise.then(() => {
55
+ if (this.#unsubscribe) {
56
+ return;
57
+ }
58
+ this.#unsubscribe = this.observer.subscribe((value) => {
59
+ this.#store.set(value);
60
+ });
61
+ if (init) {
62
+ return this.observer.send({
63
+ setup: true,
64
+ variables: get(this.observer).variables
65
+ });
66
+ }
67
+ });
68
+ }
18
69
  }
19
70
  export {
20
71
  BaseStore
@@ -1,4 +1,3 @@
1
- import type { DocumentStore } from '$houdini/runtime/client';
2
1
  import type { MutationArtifact, GraphQLObject, QueryResult } from '$houdini/runtime/lib/types';
3
2
  import type { RequestEvent } from '@sveltejs/kit';
4
3
  import { BaseStore } from './base';
@@ -9,7 +8,6 @@ export declare class MutationStore<_Data extends GraphQLObject, _Input extends {
9
8
  fetch?: typeof globalThis.fetch;
10
9
  event?: RequestEvent;
11
10
  } & MutationConfig<_Data, _Input, _Optimistic>): Promise<QueryResult<_Data, _Input>>;
12
- subscribe(...args: Parameters<DocumentStore<_Data, _Input>['subscribe']>): import("$houdini/runtime/lib").Unsubscriber;
13
11
  }
14
12
  export type MutationConfig<_Result, _Input, _Optimistic> = {
15
13
  optimisticResponse?: _Optimistic;
@@ -25,9 +25,6 @@ class MutationStore extends BaseStore {
25
25
  }
26
26
  });
27
27
  }
28
- subscribe(...args) {
29
- return this.observer.subscribe(...args);
30
- }
31
28
  }
32
29
  export {
33
30
  MutationStore
@@ -1,15 +1,12 @@
1
1
  import type { FetchContext } from '$houdini/runtime/client/plugins/fetch';
2
2
  import type { GraphQLObject, HoudiniFetchContext, MutationArtifact, QueryArtifact, QueryResult, CachePolicies } from '$houdini/runtime/lib/types';
3
3
  import type { LoadEvent, RequestEvent } from '@sveltejs/kit';
4
- import type { Readable } from 'svelte/store';
5
4
  import type { PluginArtifactData } from '../../plugin/artifactData';
6
5
  import { BaseStore } from './base';
7
6
  export declare class QueryStore<_Data extends GraphQLObject, _Input extends {}> extends BaseStore<_Data, _Input, QueryArtifact> {
8
- #private;
9
7
  variables: boolean;
10
8
  kind: "HoudiniQuery";
11
9
  protected loadPending: boolean;
12
- protected subscriberCount: number;
13
10
  protected storeName: string;
14
11
  constructor({ artifact, storeName, variables }: StoreConfig<_Data, _Input, QueryArtifact>);
15
12
  /**
@@ -19,8 +16,6 @@ export declare class QueryStore<_Data extends GraphQLObject, _Input extends {}>
19
16
  fetch(params?: LoadEventFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
20
17
  fetch(params?: ClientFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
21
18
  fetch(params?: QueryStoreFetchParams<_Data, _Input>): Promise<QueryResult<_Data, _Input>>;
22
- get name(): string;
23
- subscribe(...args: Parameters<Readable<QueryResult<_Data, _Input>>['subscribe']>): () => void;
24
19
  }
25
20
  export type StoreConfig<_Data extends GraphQLObject, _Input, _Artifact> = {
26
21
  artifact: _Artifact & {
@@ -1,29 +1,24 @@
1
- import { DocumentStore } from "$houdini/runtime/client";
2
1
  import * as log from "$houdini/runtime/lib/log";
3
2
  import { ArtifactKind, CachePolicy, CompiledQueryKind } from "$houdini/runtime/lib/types";
4
3
  import { get } from "svelte/store";
5
4
  import { clientStarted, isBrowser } from "../adapter";
6
- import { getClient, initClient } from "../client";
5
+ import { initClient } from "../client";
7
6
  import { getSession } from "../session";
8
7
  import { BaseStore } from "./base";
9
8
  class QueryStore extends BaseStore {
10
9
  variables;
11
10
  kind = CompiledQueryKind;
12
11
  loadPending = false;
13
- subscriberCount = 0;
14
12
  storeName;
15
- #store;
16
- #unsubscribe = null;
17
13
  constructor({ artifact, storeName, variables }) {
18
14
  const fetching = artifact.pluginData?.["houdini-svelte"].isManualLoad !== true;
19
15
  super({ artifact, fetching });
20
16
  this.storeName = storeName;
21
17
  this.variables = variables;
22
- this.#store = new DocumentStore({ artifact, client: null, fetching });
23
18
  }
24
19
  async fetch(args) {
25
20
  await initClient();
26
- await this.#setup(false);
21
+ this.setup();
27
22
  const { policy, params, context } = await fetchParams(this.artifact, this.storeName, args);
28
23
  if (!isBrowser && !(params && "fetch" in params) && (!params || !("event" in params))) {
29
24
  log.error(contextError(this.storeName));
@@ -71,46 +66,6 @@ This will result in duplicate queries. If you are trying to ensure there is alwa
71
66
  }
72
67
  return get(this.observer);
73
68
  }
74
- get name() {
75
- return this.artifact.name;
76
- }
77
- #setup(init = true) {
78
- let initPromise = Promise.resolve();
79
- try {
80
- getClient();
81
- } catch {
82
- initPromise = initClient();
83
- }
84
- initPromise.then(() => {
85
- if (this.#unsubscribe) {
86
- return;
87
- }
88
- this.#unsubscribe = this.observer.subscribe((value) => {
89
- this.#store.set(value);
90
- });
91
- if (init) {
92
- return this.observer.send({
93
- setup: true,
94
- variables: get(this.observer).variables
95
- });
96
- }
97
- });
98
- }
99
- subscribe(...args) {
100
- const bubbleUp = this.#store.subscribe(...args);
101
- if (isBrowser && (this.subscriberCount === 0 || !this.#unsubscribe)) {
102
- this.#setup();
103
- }
104
- this.subscriberCount = (this.subscriberCount ?? 0) + 1;
105
- return () => {
106
- this.subscriberCount--;
107
- if (this.subscriberCount <= 0) {
108
- this.#unsubscribe?.();
109
- this.#unsubscribe = null;
110
- bubbleUp();
111
- }
112
- };
113
- }
114
69
  }
115
70
  async function fetchParams(artifact, storeName, params) {
116
71
  let policy = params?.policy;
@@ -1,4 +1,3 @@
1
- import type { DocumentStore } from '$houdini/runtime/client';
2
1
  import type { SubscriptionArtifact } from '$houdini/runtime/lib/types';
3
2
  import type { GraphQLObject } from 'houdini';
4
3
  import { BaseStore } from './base';
@@ -7,8 +6,8 @@ export declare class SubscriptionStore<_Data extends GraphQLObject, _Input exten
7
6
  constructor({ artifact }: {
8
7
  artifact: SubscriptionArtifact;
9
8
  });
10
- subscribe(...args: Parameters<DocumentStore<_Data, _Input>['subscribe']>): import("$houdini/runtime/lib").Unsubscriber;
11
9
  listen(variables?: _Input, args?: {
12
10
  metadata: App.Metadata;
13
11
  }): Promise<void>;
12
+ unlisten(): Promise<void>;
14
13
  }
@@ -7,9 +7,6 @@ class SubscriptionStore extends BaseStore {
7
7
  constructor({ artifact }) {
8
8
  super({ artifact });
9
9
  }
10
- subscribe(...args) {
11
- return this.observer?.subscribe(...args);
12
- }
13
10
  async listen(variables, args) {
14
11
  await initClient();
15
12
  this.observer.send({
@@ -18,6 +15,10 @@ class SubscriptionStore extends BaseStore {
18
15
  metadata: args?.metadata
19
16
  });
20
17
  }
18
+ async unlisten() {
19
+ await initClient();
20
+ await this.observer.cleanup();
21
+ }
21
22
  }
22
23
  export {
23
24
  SubscriptionStore