@aerogel/plugin-solid 0.1.1 → 0.1.2-next.09ce77256b928c50029720116feccc246da1293c

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.
Files changed (56) hide show
  1. package/LICENSE +21 -0
  2. package/dist/InruptAuthenticator.lazy-DlPdapoE.js +2 -0
  3. package/dist/LegacyAuthenticator.lazy-ghwPx9kV.js +2 -0
  4. package/dist/{aerogel-plugin-solid.d.ts → index.d.ts} +136 -28
  5. package/dist/index.js +4047 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/models-worker.d.ts +32 -0
  8. package/dist/models-worker.js +63 -0
  9. package/dist/models-worker.js.map +1 -0
  10. package/dist/setup-vitest.d.ts +32 -0
  11. package/dist/setup-vitest.js +11 -0
  12. package/dist/setup-vitest.js.map +1 -0
  13. package/dist/soukai-fKvaZSAB.js +13 -0
  14. package/dist/soukai-fKvaZSAB.js.map +1 -0
  15. package/package.json +57 -45
  16. package/src/auth/Authenticator.ts +12 -12
  17. package/src/auth/authenticators/InruptAuthenticator.ts +14 -15
  18. package/src/auth/authenticators/LegacyAuthenticator.ts +6 -10
  19. package/src/auth/index.ts +3 -2
  20. package/src/components/SolidAvatar.vue +2 -4
  21. package/src/components/SolidImage.vue +2 -3
  22. package/src/components/SolidLogin.vue +14 -30
  23. package/src/errors/AuthenticationFailedError.ts +0 -2
  24. package/src/errors/ContainerAlreadyInUse.ts +2 -4
  25. package/src/forms/index.ts +1 -0
  26. package/src/forms/schemas.ts +6 -0
  27. package/src/index.test.ts +16 -5
  28. package/src/index.ts +40 -24
  29. package/src/models-worker.ts +71 -0
  30. package/src/services/Solid.state.ts +5 -6
  31. package/src/services/Solid.ts +144 -121
  32. package/src/services/index.ts +14 -0
  33. package/src/setup-vitest.ts +9 -0
  34. package/src/testing/index.ts +9 -0
  35. package/src/testing/runtime.ts +8 -0
  36. package/src/testing/setup.ts +13 -2
  37. package/src/testing/stubs/models/User.schema.ts +9 -0
  38. package/src/testing/stubs/models/User.ts +3 -0
  39. package/src/types/env.d.ts +1 -0
  40. package/src/types/solid-auth-client.d.ts +0 -2
  41. package/src/utils/composition.test.ts +126 -0
  42. package/src/utils/composition.ts +331 -0
  43. package/src/utils/flags.ts +3 -0
  44. package/src/utils/index.ts +2 -0
  45. package/src/utils/internal.ts +196 -0
  46. package/src/utils/services.test.ts +71 -0
  47. package/src/utils/services.ts +109 -0
  48. package/src/utils/soukai.ts +18 -0
  49. package/src/workers/ModelsWorker.ts +166 -0
  50. package/dist/InruptAuthenticator.lazy-BvpQLGoj.js +0 -9
  51. package/dist/InruptAuthenticator.lazy-BvpQLGoj.js.map +0 -1
  52. package/dist/LegacyAuthenticator.lazy-ChFFqP14.js +0 -5
  53. package/dist/LegacyAuthenticator.lazy-ChFFqP14.js.map +0 -1
  54. package/dist/aerogel-plugin-solid.js +0 -724
  55. package/dist/aerogel-plugin-solid.js.map +0 -1
  56. package/src/forms/validation.ts +0 -11
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Noel De Martin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ import { events as e, fetch as t, handleIncomingRedirect as n, login as r, logout as i } from "@inrupt/solid-client-authn-browser";
2
+ export { e as events, t as fetch, n as handleIncomingRedirect, r as login, i as logout };
@@ -0,0 +1,2 @@
1
+ import e from "solid-auth-client";
2
+ export { e as SolidAuthClient };
@@ -1,28 +1,39 @@
1
1
  import { Closure } from '@noeldemartin/utils';
2
2
  import { ComponentOptionsMixin } from 'vue';
3
3
  import { ComponentProvideOptions } from 'vue';
4
+ import { ComputedAttribute } from 'soukai-bis';
5
+ import { ComputedRef } from 'vue';
6
+ import { Container } from 'soukai-bis';
7
+ import { ContainerConstructor } from 'soukai-bis';
4
8
  import { DefineComponent } from 'vue';
5
- import { Engine } from 'soukai';
9
+ import { Engine } from 'soukai-bis';
6
10
  import { ErrorSource } from '@aerogel/core';
7
11
  import { Facade } from '@noeldemartin/utils';
8
- import { Fetch } from 'soukai-solid';
9
- import { Fetch as Fetch_2 } from '@noeldemartin/solid-utils';
12
+ import { Fetch } from '@noeldemartin/solid-utils';
10
13
  import { FluentArray } from '@noeldemartin/utils';
11
- import { GetClosureArgs } from '@noeldemartin/utils';
12
14
  import { HTMLAttributes } from 'vue';
13
15
  import { JSError } from '@noeldemartin/utils';
14
16
  import { JSErrorOptions } from '@noeldemartin/utils';
17
+ import { MaybeRefOrGetter } from 'vue';
18
+ import { Model } from 'soukai-bis';
19
+ import { ModelConstructor } from 'soukai-bis';
20
+ import { ModelEvents } from 'soukai-bis';
21
+ import { ModelListener } from 'soukai-bis';
22
+ import { ModelsRegistry } from 'soukai-bis';
23
+ import { ModelWithUrl } from 'soukai-bis';
24
+ import { Nullable } from '@noeldemartin/utils';
15
25
  import { NullablePartial } from '@noeldemartin/utils';
16
26
  import { Plugin as Plugin_2 } from '@aerogel/core';
17
27
  import { PromisedValue } from '@noeldemartin/utils';
18
28
  import { PublicProps } from 'vue';
29
+ import { Ref } from 'vue';
30
+ import { Service } from '@aerogel/core';
19
31
  import { ServiceWithState } from '@aerogel/core';
20
- import { SolidContainer } from 'soukai-solid';
21
- import { SolidEngine } from 'soukai-solid';
22
- import { SolidModelConstructor } from 'soukai-solid';
32
+ import { SolidEngine } from 'soukai-bis';
23
33
  import { SolidStore } from '@noeldemartin/solid-utils';
24
- import { SolidTypeIndex } from 'soukai-solid';
25
34
  import { SolidUserProfile } from '@noeldemartin/solid-utils';
35
+ import { TypeIndex } from 'soukai-bis';
36
+ import { z } from 'zod';
26
37
 
27
38
  declare type __VLS_Props = {
28
39
  src: string;
@@ -50,7 +61,7 @@ export declare abstract class Authenticator {
50
61
  protected booted?: PromisedValue<void>;
51
62
  protected listeners: FluentArray<AuthenticatorListener>;
52
63
  protected _engine?: SolidEngine;
53
- abstract login(loginUrl: string, user?: SolidUserProfile | null): Promise<AuthSession>;
64
+ abstract login(loginUrl: string, options?: AuthenticatorLoginOptions): Promise<AuthSession>;
54
65
  abstract logout(): Promise<void>;
55
66
  get engine(): Engine;
56
67
  getAuthenticatedFetch(): Fetch | null;
@@ -73,6 +84,10 @@ export declare interface AuthenticatorListener {
73
84
  onAuthenticatedFetchReady?: (fetch: Fetch) => Promise<void> | void;
74
85
  }
75
86
 
87
+ export declare interface AuthenticatorLoginOptions {
88
+ user?: Nullable<SolidUserProfile>;
89
+ }
90
+
76
91
  export declare type AuthenticatorName = keyof Authenticators;
77
92
 
78
93
  export declare interface Authenticators extends BaseAuthenticators {
@@ -92,22 +107,32 @@ export declare interface AuthSession {
92
107
 
93
108
  declare type BaseAuthenticators = typeof authenticators;
94
109
 
110
+ export declare function computedModel<T>(compute: () => T): Readonly<Ref<T>>;
111
+
112
+ export declare function computedModelAttribute<TModel extends Model, TAttribute extends string & keyof TModel>(model: MaybeRefOrGetter<TModel | null | undefined>, attribute: TAttribute): TModel[TAttribute] extends ComputedAttribute<infer T> ? Readonly<Ref<T | undefined>> : never;
113
+
114
+ export declare function computedModels<T>(modelClass: ModelConstructor, compute: () => T, options?: ComputedModelsOptions): ComputedRef<T>;
115
+
116
+ export declare interface ComputedModelsOptions {
117
+ watch?: string[];
118
+ }
119
+
95
120
  export declare class ContainerAlreadyInUse extends JSError {
96
- constructor(container: SolidContainer, options?: JSErrorOptions);
121
+ constructor(container: Container, options?: JSErrorOptions);
97
122
  }
98
123
 
99
124
  declare const _default: ServiceWithState< {
100
125
  autoReconnect: boolean;
101
126
  dismissed: boolean;
102
127
  ignorePreviousSessionError: boolean;
103
- loginStartupError: ErrorSource | null;
128
+ loginStartupError: ErrorSource;
104
129
  loginOngoing: boolean;
105
130
  preferredAuthenticator: AuthenticatorName | null;
106
131
  previousSession: {
107
132
  profile?: SolidUserProfile;
108
133
  authenticator: AuthenticatorName;
109
134
  loginUrl: string;
110
- error: ErrorSource | null;
135
+ error: ErrorSource;
111
136
  } | null;
112
137
  profiles: Record<string, SolidUserProfile>;
113
138
  session: AuthSession | null;
@@ -116,20 +141,20 @@ staleProfiles: string[];
116
141
  }, {
117
142
  user: SolidUserProfile | null;
118
143
  authenticator: Authenticator | null;
119
- fetch: Fetch_2;
144
+ fetch: Fetch;
120
145
  error: unknown;
121
146
  }, Partial<{
122
147
  autoReconnect: boolean;
123
148
  dismissed: boolean;
124
149
  ignorePreviousSessionError: boolean;
125
- loginStartupError: ErrorSource | null;
150
+ loginStartupError: ErrorSource;
126
151
  loginOngoing: boolean;
127
152
  preferredAuthenticator: AuthenticatorName | null;
128
153
  previousSession: {
129
154
  profile?: SolidUserProfile;
130
155
  authenticator: AuthenticatorName;
131
156
  loginUrl: string;
132
- error: ErrorSource | null;
157
+ error: ErrorSource;
133
158
  } | null;
134
159
  profiles: Record<string, SolidUserProfile>;
135
160
  session: AuthSession | null;
@@ -137,8 +162,14 @@ loginStale: boolean;
137
162
  staleProfiles: string[];
138
163
  }>>;
139
164
 
165
+ export declare function findTrackedModel<T extends Model>(modelClass: ModelConstructor<T>, url: string): Promise<T | null>;
166
+
140
167
  export declare function getAuthenticator<T extends AuthenticatorName>(name: T): Authenticators[T];
141
168
 
169
+ export declare function getTrackedModels<T extends Model>(modelClass: ModelConstructor<T>, options?: {
170
+ includeSoftDeleted?: boolean;
171
+ }): T[];
172
+
142
173
  declare class InruptAuthenticator extends Authenticator {
143
174
  private _events;
144
175
  private _fetch;
@@ -152,41 +183,61 @@ declare class InruptAuthenticator extends Authenticator {
152
183
  protected initSession(webId: string): Promise<void>;
153
184
  }
154
185
 
186
+ export declare function isTrackingModel(modelClass: ModelConstructor): boolean;
187
+
155
188
  declare class LegacyAuthenticator extends Authenticator {
156
189
  private store;
157
190
  constructor();
158
- login(loginUrl: string, user?: SolidUserProfile | null): Promise<AuthSession>;
191
+ login(loginUrl: string, { user }?: AuthenticatorLoginOptions): Promise<AuthSession>;
159
192
  logout(): Promise<void>;
160
193
  protected restoreSession(): Promise<void>;
161
194
  }
162
195
 
163
196
  declare type ListenerEvent = keyof AuthenticatorListener;
164
197
 
165
- declare type ListenerEventPayload<Event extends ListenerEvent, Callback = AuthenticatorListener[Event]> = Callback extends Closure ? GetClosureArgs<Callback> : never;
198
+ declare type ListenerEventPayload<Event extends ListenerEvent, Callback = AuthenticatorListener[Event]> = Callback extends Closure ? Parameters<Callback> : never;
199
+
200
+ export declare function loadTrackedModels(modelClass: ModelConstructor): Promise<void>;
166
201
 
167
202
  export declare type LoginOptions = NullablePartial<{
168
203
  authenticator: AuthenticatorName;
169
204
  onError(error: ErrorSource): unknown;
170
205
  fallbackUrl: string;
171
206
  loading: boolean;
207
+ skipProfile?: boolean;
208
+ extra?: Record<string, unknown>;
209
+ }>;
210
+
211
+ declare function model<T extends keyof ModelsRegistry>(name: T): ModelsRegistry[T];
212
+
213
+ declare function model<T extends ModelConstructor = ModelConstructor>(name: string): T;
214
+
215
+ export declare type ModelService<TModel extends Model = Model, TKey extends string = string> = Service<{
216
+ [K in TKey]: TModel[];
172
217
  }>;
173
218
 
174
219
  export declare interface Options {
175
220
  autoReconnect?: boolean;
176
221
  authenticators?: Record<string, Authenticator>;
177
- defaultAuthenticator?: AuthenticatorName;
178
- onUserProfileLoaded?(user: SolidUserProfile, store: SolidStore): Promise<unknown> | unknown;
222
+ defaultAuthenticator?: AuthenticatorName | (() => AuthenticatorName);
223
+ onUserProfileLoaded?(user: SolidUserProfile, store: SolidStore): unknown;
179
224
  }
180
225
 
181
226
  export declare type ReconnectOptions = Omit<LoginOptions, 'authenticator'> & {
182
227
  force?: boolean;
183
228
  };
184
229
 
230
+ export declare function refreshTrackedModels(modelClass: ModelConstructor): Promise<void>;
231
+
232
+ export declare type RefValue<T> = T extends Ref<infer TValue> ? TValue : never;
233
+
185
234
  export declare function registerAuthenticator<T extends AuthenticatorName>(name: T, authenticator: Authenticators[T]): void;
186
235
 
187
236
  export declare function registerAuthenticators(customAuthenticators: Record<string, Authenticator>): void;
188
237
 
189
- declare const services: {
238
+ export declare function resetModelsState(): void;
239
+
240
+ export declare const services: {
190
241
  $solid: Facade<SolidService>;
191
242
  };
192
243
 
@@ -199,11 +250,14 @@ export default solid;
199
250
 
200
251
  export declare const SolidAvatar: DefineComponent< {}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {}, HTMLDivElement>;
201
252
 
253
+ export declare function solidContainerUrl(): z.ZodString;
254
+
202
255
  export declare const SolidImage: DefineComponent<__VLS_Props, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, HTMLImageElement>;
203
256
 
204
257
  export declare const SolidLogin: DefineComponent<__VLS_Props_2, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props_2> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, HTMLFormElement>;
205
258
 
206
259
  export declare class SolidService extends _default {
260
+ private _engine?;
207
261
  isLoggedIn(): this is {
208
262
  session: AuthSession;
209
263
  user: SolidUserProfile;
@@ -216,6 +270,7 @@ export declare class SolidService extends _default {
216
270
  user: SolidUserProfile;
217
271
  };
218
272
  requireAuthenticator(): Authenticator;
273
+ requireEngine(): SolidEngine;
219
274
  requireUser(): SolidUserProfile;
220
275
  requireUserProfile(url: string): Promise<SolidUserProfile>;
221
276
  getUserProfile(url: string, options: Omit<UserProfileOptions, 'required'> & {
@@ -228,23 +283,24 @@ export declare class SolidService extends _default {
228
283
  logout(force?: boolean): Promise<void>;
229
284
  whenLoggedIn<T>(callback: (session: AuthSession) => T): Promise<T>;
230
285
  dismiss(): void;
231
- findOrCreatePrivateTypeIndex(): Promise<SolidTypeIndex>;
286
+ findRegisteredContainer<T extends Container = Container>(modelClass: ModelConstructor, containerClass?: ContainerConstructor<T>): Promise<T | null>;
287
+ findTypeIndexes(): Promise<ModelWithUrl<TypeIndex>[]>;
288
+ findOrCreatePrivateTypeIndex(): Promise<ModelWithUrl<TypeIndex>>;
232
289
  findPrivateTypeIndex(options?: {
233
290
  fresh?: boolean;
234
- }): Promise<SolidTypeIndex | null>;
235
- findOrCreatePublicTypeIndex(): Promise<SolidTypeIndex>;
291
+ }): Promise<ModelWithUrl<TypeIndex> | null>;
236
292
  findPublicTypeIndex(options?: {
237
293
  fresh?: boolean;
238
- }): Promise<SolidTypeIndex | null>;
294
+ }): Promise<ModelWithUrl<TypeIndex> | null>;
295
+ clearTypeIndexesCache(): void;
239
296
  createPrivateContainer(options: {
240
297
  url: string;
241
298
  name?: string;
242
- registerFor?: SolidModelConstructor;
299
+ registerFor?: ModelConstructor;
243
300
  reuseExisting?: boolean;
244
- }): Promise<SolidContainer>;
301
+ }): Promise<ModelWithUrl<Container>>;
245
302
  protected boot(): Promise<void>;
246
- protected createPrivateTypeIndex(): Promise<SolidTypeIndex>;
247
- createPublicTypeIndex(): Promise<SolidTypeIndex>;
303
+ protected createPrivateTypeIndex(): Promise<ModelWithUrl<TypeIndex>>;
248
304
  protected attemptLogin(loginUrl: string, options: LoginOptions): Promise<boolean>;
249
305
  private restorePreviousSession;
250
306
  private startupReconnect;
@@ -256,6 +312,45 @@ export declare class SolidService extends _default {
256
312
 
257
313
  export declare type SolidServices = typeof services;
258
314
 
315
+ export declare type SolidTestingRuntime = typeof testingRuntime;
316
+
317
+ declare namespace testingRuntime {
318
+ export {
319
+ model
320
+ }
321
+ }
322
+ export { testingRuntime }
323
+
324
+ export declare interface TrackCollectionsOptions {
325
+ refresh?: boolean;
326
+ }
327
+
328
+ export declare function trackModels<TModel extends Model, TKey extends string>(modelClass: ModelConstructor<TModel>, options?: TrackOptions<TModel, TKey>): Promise<void>;
329
+
330
+ export declare type TrackOptions<TModel extends Model = Model, TKey extends string = string> = {
331
+ service?: ModelService<TModel, TKey>;
332
+ property?: TKey;
333
+ transform?: (models: TModel[]) => TModel[];
334
+ depth?: number;
335
+ lazy?: boolean;
336
+ bypassServicesCheck?: boolean;
337
+ } & {
338
+ [K in keyof ModelEvents]?: ModelListener<TModel, K>;
339
+ };
340
+
341
+ export declare function useModelEvent<TModel extends Model, TEvent extends keyof ModelEvents>(modelClass: ModelConstructor<TModel>, event: TEvent, listener: ModelListener<TModel, TEvent>): void;
342
+
343
+ export declare function useModels<T extends Model>(modelClass: ModelConstructor<T>, options?: {
344
+ includeSoftDeleted?: boolean;
345
+ depth?: number;
346
+ }): UseModelsResult<T>;
347
+
348
+ export declare interface UseModelsResult<T extends Model> {
349
+ models: ComputedRef<T[]>;
350
+ loading: ComputedRef<boolean>;
351
+ refreshing: Readonly<Ref<boolean>>;
352
+ }
353
+
259
354
  export declare type UserProfileOptions = NullablePartial<{
260
355
  required: boolean;
261
356
  markStale: boolean;
@@ -264,6 +359,12 @@ export declare type UserProfileOptions = NullablePartial<{
264
359
  export { }
265
360
 
266
361
 
362
+ declare module '@aerogel/core' {
363
+ interface AerogelTestingRuntime extends SolidTestingRuntime {
364
+ }
365
+ }
366
+
367
+
267
368
  declare module '@aerogel/core' {
268
369
  interface Services extends SolidServices {
269
370
  }
@@ -280,3 +381,10 @@ declare module '@aerogel/core' {
280
381
  'solid:user-profile-loaded': [SolidUserProfile, SolidStore];
281
382
  }
282
383
  }
384
+
385
+
386
+ declare module '@aerogel/core' {
387
+ interface EventsPayload {
388
+ 'solid:track-models': ModelConstructor;
389
+ }
390
+ }